This is a discussion on javascript querystring within the PHP Language forums, part of the PHP Programming Forums category; Hi guys, I have this html file containing: <html><head> <script src="variable.js?...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi guys,
I have this html file containing: <html><head> <script src="variable.js?id=1004"></script> </head><body></body></html> I also have the .js file that looks like this ---------------------------------------------------------------------------------------- var id = getQueryVariable("id"); function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); var returned = 0; for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (pair[0] == variable) { returned = pair[1]; } } return returned; } document.write(id); ----------------------------------------------------------------------------------------- I do a mistake somewhere and I don't get back the value of the id in the querystring. I get the value displayed only if i add the querystring at the end of the html file name in the browser's address line. It might be a small problem, but I know very little JavaScript so I require your help. Thanks in advance |
|
|||
|
After reading more posts I have the solution.
Maybe will be of use to some HTML FILE contains ------------------------------------------ <script type="text/javascript"> var id = "1004"; </script> <script type="text/javascript" src="myletter.js"> </script> ------------------------------------------------------------------------------- JAVASCRIPT FILE contains ------------------------------------------------ var id = (id); document.write(id); ------------------------------------------------ More simple than I thought. |