aspx Tutorial

NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Thursday, May 17, 2012 Total Views:  

 

In this post, you will see how to get querystring value from a URL on client side by using javscript.  

Javascript function

    <script type="text/javascript">

        QueryString = function (str) {

            var url = window.location.search.substring(1).split('&');

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

                var Name = url[i].split('=');

                if (Name[0] == str)

                    return Name[1];

            }

        };

    </script>

 

    <script type="text/javascript">

        alert(QueryString("firstName"));

        alert(QueryString("lastName"));

    </script>

 

URL

http://www.aspxtutorial.com/demo/Jquery/QueryString.aspx?firstName=Aamir&lastName=Hasan

 

In the above URL, I have passed firstName and lastName querystring values.

Above you will notice that I have called querystring function twice and passed variable name to get value of querystring from URL.

 

Note: Function will return undefined if when there is no querystring is passed in the URL.
 

 

Above function has been tested on following browsers (IE, firefox, chrome, safari, ipad, iphone and opera)

 Output

view demo

Protected by Copyscape Online Plagiarism Tool

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5