How to pass Query String value from java script


In this article I have explained about how to pass Query String value from java script with Example. Each steps I have clearly explained in this article.


In this example I'm passing Querystring value to other pages with help of window.open function.
To split the url using split method.



var vquery = window.location.search.substring(1);
alert(vquery);


In First Page:-






<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Passing Query String Values between pages</title>

<script type="text/javascript" language="javascript">
function PassQueryStringValue()
{
var vQueryStringVal = "Welcome";
alert("DisplayQueryString.aspx?Qid=" + vQueryStringVal+"&dotnetspider");
window.open("DisplayQueryString.aspx?Qid=" + vQueryStringVal+"& Qid1=dotnetspider");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="PassQueryStringValue();" />
</div>
</form>
</body>
</html>


To get the Query string value we can use GetQueryStringValue



In Second Page:-



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function GetQueryStringValue()
{

var vquery = window.location.search.substring(1);

var vparms = vquery.split('&');

for (var i=0; i <vparms.length; i++)

{

var vpos = vparms[i].indexOf('=');

if (vpos > 0) {

var vkey = vparms[i].substring(0,vpos);

var vval = vparms[i].substring(vpos+1);

alert(vval);

}

}

}

</script>
</head>
<body onload="GetQueryStringValue()">
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: