Best Jquery ,javascript, HTML5 CSS3 tutorial with jquery examples, php script , demos for beginners, web designers and web developers.

Jquery

Jquery Training

Jquery training blog

Replace or update the parameter value of url query string in Javascript

In this post I am going to discuss about url query string and some of simple but critical issues arise in time of web development. These are javascript issues. There are lots of issues but whatever I faced, going to discuss with example in this post. Replace or update the parameter value of query string Continue Reading


In this post I am going to discuss about url query string and some of simple but critical issues arise in time of web development. These are javascript issues. There are lots of issues but whatever I faced, going to discuss with example in this post.

  1. Replace or update the parameter value of query string in url in Javascript.
  2. Foreach the values of array  and show the array element value in same div in javascript

 

url in Javascript

Replace or update the parameter value of url query string in Javascript:
The below example showing the parameter before update.The url appending the query string instead of updating like,

http://localhost/?text=abc&text=123&text=xyz

<html>
<head>
<title>Replace or update the parameter value of query string in url in Javascript</title>
</head>

<body>
<input type="text" name="textsearch" id="textsearch">
<a href="" id="goto" onclick="updateBefore();">Before update</a>

<script>

function updateBefore(){
var textvalue=document.getElementById("textsearch").value;
document.getElementById("goto").href=window.location.href+'?text='+textvalue;
}
</script>
</body>
</html>

The below example showing the parameter after update.The url updating the query string value, each time when it reload on click on some other mean.

Suppose on click we are updating query sting value. On first click the url will be

http://localhost/?text=abc

On second click the url will be

http://localhost/?text=123

See the url example in first click the value of query string ‘text’ is abc and on second click the value of query string ‘text’ is 123

<html>
<head>
<title>Replace or update the parameter value of query string in url in Javascript</title>
</head>

<body>
<input type="text" name="textsearch" id="textsearch">
<a href="" id="goto" onclick="updateAfter();">Adfter update</a>
<script>
function updateAfter(){
var textvalue=document.getElementById("textsearch").value;
var turl=window.location.href ;
if(turl.indexOf("text") > -1) {
var updatedurl = turl.replace(/(text=)[^\&]+/, '$1' + textvalue);
document.getElementById("goto").href=updatedurl;
}else{
document.getElementById("goto").href=window.location.href+'?text='+textvalue;
}
}
</script>
</body>
</html>

<html>
<head>
 <title>Foreach array in javscript and append array value in div </title>
</head>

<body>

Foreach value s of array ["a", "b", "c"] and show the each arry element value in a div
<div id="foreachloop_in_javascript"></div>


<script>
var a = ["a", "b", "c"];
a.forEach(function(entry) {
 var theDiv = document.getElementById("foreachloop_in_javascript");
 var content = document.createTextNode(entry+', ');
 theDiv.appendChild(content);
 
});
</script>
</body>
</html>

Please follow and like us:






About the author

Joydeb Choudhury holds a Master's degree in Computer Application from I.G.N.O.U. After working as a web developer in various companies he has started bloging in 2016.

Recent Posts of blog

Downalod Free Php Scripts