javascript querystring

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi guys,

I have this html file containing:

<script src="variable.js?id=1004"></script>

I also have the .js file that looks like this
var id = getQueryVariable("id");
function getQueryVariable(variable)
  var query =;
  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;

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

Re: javascript querystring

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 type="text/javascript" src="myletter.js"> </script>

var id = (id);

More simple than I thought.

Site Timeline