SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot Da Mouse's Avatar
    Join Date
    Aug 2002
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query String parsing script is buggered

    it doesn't show what ?n is equal to at the end document.write()
    Code:
    <script>
    var newqstring = this.location.href.substring(this.location.href.indexOf('?')+1).split(";");
    var _MOUS = new Array();
    for(var q=0;q<newqstring.length;q++)
    {
    	if(newqstring[q] != "")
    	{
    		var dynamic = newqstring[q].split("=");
    		var _MOUS[dynamic[0]] = dynamic[1];
    	}
    }
    document.write(_MOUS['n']);
    </script>
    I am DaMouse
    Nobody can beat me so long as I'm stubborn -DaMouse
    Squeak

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wrote a function for that. Here it is, plus a sample use for you...
    Code:
    <script>
    function parseGetVars() {
    	var getVars = new Array();
    	var qString = top.location.search.substring(1);
    	var pairs = qString.split(/\&/);
    	for (var i in pairs) {
    		var nameVal = pairs[i].split(/\=/);
    		getVars[unescape(nameVal[0])] = unescape(nameVal[1]);
    		}	
    	return getVars;
    	}
    var _MOUS = parseGetVars();
    </script>
    
    <script>
    document.write(_MOUS['n']);
    </script>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Member dotjeff's Avatar
    Join Date
    Dec 2002
    Location
    Oregon
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How about a different approach?

    Hi,

    It looks like you need a really simply solution for parsing the query string. I wrote a small script that does all the work for you. Check it out:

    http://members.evolt.org/jeff/code/j...bles/index.cfm

    Enjoy,

    Jeff (.jeff)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •