Saturday, August 28, 2010

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

No comments:

Popular Posts