Introduction:
Description:
In previous articles I explained jQuery get query string parameter values, jQuery Remove first/last character from string, Best Drag and Drop Plugin examples, Scroll back to top plugin Examples, jQuery create rounded corners for textbox and many articles relating to JQuery. Now I will explain how to get query string parameter value with space using JQuery.
In previous articles I explained jQuery get query string parameter values, jQuery Remove first/last character from string, Best Drag and Drop Plugin examples, Scroll back to top plugin Examples, jQuery create rounded corners for textbox and many articles relating to JQuery. Now I will explain how to get query string parameter value with space using JQuery.
To
get query string parameter value with spaces we need to use decodeURIComponent JavaScript
function in our
code like as shown below
<script type="text/javascript">
$ (function()
{
var str = decodeURIComponent('Welcome%20To%20Aspdotnet-Suresh')
alert(str);
})
</script>
|
If
you want check this code in sample check below code
Example:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Get Query String Parameter Values with Spaces</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 decodeURIComponent(urlparam[1]);
}
}
}
</script>
</head>
<body>
<form id="form1"
runat="server">
<div>
<p>UserName: <span id="spn_UserName"></span></p>
<p>UserId: <span id="spn_UserId"></span></p>
</div>
</form>
</body>
</html>
|
Live
Demo
To check above
example I given ur like “http://aspdotnet-suresh.com/test.aspx?username=Welcome%20To%20Aspdotnet-Suresh
&userid=2” and it return values like as shown below
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.