jquery - Using Javascript to get URL Vars, not working when multiple values present in QueryString -
I use a javascript function to get the value of the URL to pass jQuery using the given function I am doing:
getUrlVars function () {var vars = [], hash; Var hashes = window.location.href.slice (window.location.href.indexOf ('?') + 1) .split ('& amp;'); For (var i = 0; i & lt; hashes.length; i ++) {hash = hash [i] .split ('='); Vars.push (hash [0]); Wars [hash [0]] = hash [1]; } Returns Wars; }
and then set the value like this:
var type = getUrlVars () ["type"]
It all works perfectly, but I have just come in a situation where I need to get multiple values, one of my form elements is a checkbox where multiple values can be checked, so My URL would look something like this:
http://www.domain.com/test.php?type=1&cuisine[]=23&cuisine[]=43&name=test
If I above the funk Connection extend the alert, the value of recipes using, so I only get the final price:
alert (getUrlVars () [ "food []"]);
"43" will warn.
How would I like it, it is a comma-delimited string of all "recipes" values that means "23,43" in the example given above
Any help is very welcome! If any solutions are required, then I am using PHP 5.3 and Jquery 1.4.
function getUrlVars () {Var Vars = [], hash; Var hashes = window.location.href.slice (window.location.href.indexOf ('?') + 1) .split ('& amp;'); For (var i = 0; i & lt; hashes.length; i ++) {hash = hash [i] .split ('='); If ($ .inArray (hash [0], Wars)> 1) Wars {hash [0]] + = "," + hash [1]; } And {vars.push (hash [0]); Wars [hash [0]] = hash [1]; }} Returns Wars; }
Comments
Post a Comment