Pages

Thursday, May 5, 2011

Get query string values from javascript easily


Use the simple javascript function
<script type="text/javascript">

function querystring(qstr)
{

qstr  = window.location.search.substring(1);

q_vars = qstr.split("&");

for (i=0;i<q_vars.length;i++)
{

ft = q_vars[i].split("=");

if (ft[0] == qstr)
{

return ft[1];

}

}

}
</script>

Call using querystring("string")

Sample : www.example.com/index.php?name=aravind&place=venjaramood

var reqQrstr= querystring("name");
document.write(reqQrstr);

Will output : aravind


0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.