Accessing querystring value using JavaScript

When I was working with server-side script, I have the question its possible to access query-string values from JavaScript. But which way it will be identify the each parameters from the query-string.

In JavaScript we have method “window.location.href” which will read url and query-string. We will create two html file, first one will have text-box and submit, second html file will display query-string in webpage.


<form action="result.html" method="get">
<td><input type="text" name="txtName" /></td>
<td><input type="text" name="txtAge" /></td>
<td><input type="submit" name="btnSubmit" value="Submit" /></td>


// reading url and splitting url and parameters
var result = window.location.href.split("?");

// splitting the parameters
var r = result[1].split("&");
var arr = [];

for(k in r) {
	// splitting the parameters for name and values
	v = r[k].split("=");

	// pushing the name and value into array
	arr.push(v[0]+"_"+v[1]+"<br />");

// last printing the array

[ Download ] | [ Demo ]