Darkmatter5 Posted December 9, 2008 Share Posted December 9, 2008 If I have the following URL http://www.site.com/res_filing.php?cab=4&fol=1&item=8 How can I extract cab, fol and item from the url into variables named cab_id, fol_id and item_id for use in a javascript function? Link to comment https://forums.phpfreaks.com/topic/136269-create-variables-from-url-variable-passing/ Share on other sites More sharing options...
Psycho Posted December 9, 2008 Share Posted December 9, 2008 function getURLVar(varName) { url = unescape(self.document.location); if (varstring = url.substring(url.indexOf('?')+1)) { varpairs = varstring.split(/&/); for (i=0; i<varpairs.length; i++) { varpair = varpairs[i].split(/=/); if (varName==varpair[0]) { return varpair[1]; } } } return false; } var cab_id = getURLVar(cab); var fol_id = getURLVar(fol); var item_id = getURLVar(item); Link to comment https://forums.phpfreaks.com/topic/136269-create-variables-from-url-variable-passing/#findComment-710931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.