Friday, June 6, 2014

How to get Values From Query String Using Jquery

<head>
<title>jQuery Get Current Page Url Parameter values</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
var name = GetParameterValues('username');
var id = GetParameterValues('userid');
$('#spn_UserName').html('<strong>' + name + '</strong>');
$('#spn_UserId').html('<strong>' + id + '</strong>');
});
function GetParameterValues(param) {
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < url.length; i++) {
var urlparam = url[i].split('=');
if (urlparam[0] == param) {
return urlparam[1];
}
}
}
</script>
</head>
<body>
<a href="?username=sandeep&userid=23">click here</a>
<form id="form1" runat="server" action="">
<div>
<p>UserName: <span id="spn_UserName"></span></p>
<p>UserId: <span id="spn_UserId"></span></p>
</div>
</form>
</body>
</html>

text this code on your browser