snippet library logo
Amazon.com
in category
Javascript / Forms / Parse query string
Snippet details
ID: 524
Viewed: 970
Added: 2004-01-24
Version: 1.0
View Demo

User Rated at: 5 Stars
Rate This:
Snippets in this catagory         
Show Printable Version
A function for getting data from the query string.

General Details
Snippet uploaded by: agent002
Email : zzzleepy89@hotmail.com
Snippet By: agent002

<!---Head--->
<script type="text/javascript"><!--
// Query string is:
//   firstname=John&lastname=Doe
// Get value for 'firstname':
//   var firstname = GetQuery('firstname');
// (The script automatically unescapes the value).

function GetQuery(arg){
    var query = location.href.substring((location.href.indexOf('?') + 1), location.href.indexOf('#'));
    if(location.href.indexOf('#') < location.href.indexOf('?')){
        query = location.href.substring((location.href.indexOf('?') + 1), location.href.length);
    }
    if(location.href.indexOf('?') < 0){
        query = '';
    }
    var querypairs = query.split('&');
    var ret = '';
    for(var i = 0; i < querypairs.length; i++){
        var namevalue = querypairs[i].split('=');
        if(namevalue[0] && namevalue[1] && namevalue[0] == arg){
            while(namevalue[1].indexOf('+') >= 0){
                namevalue[1] = namevalue[1].replace('+', ' ');
            }
            ret = unescape(namevalue[1]);
        }
    }
    return ret;
}
--></script>

<!---Body--->


haha




No Reviews to show


Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Subject:

Reviewed By:

Write a review:





Terms of Conditions
Powered By
Avian Hosting
© 2005 snippetlibrary.com All Rights Reserved.