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? Quote Link to comment 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.