View Full Version : Accessing A javascript variable in HTML

03-15-2009, 06:07 AM
Hi All,

I have two Select Boxes on my web page, 2nd being populated based on selection of first select box.

Now I am suppose to get the selected value of 2nd Select and put it in a link i.e. <a href='abc.html?id=<2nd select box value>' .

I can get the selected value using Javascript with the following code:

2ndid = form.2ndodf.options[form.2ndodf.options.selectedIndex].value;

where 2ndid is a global javascript variable.

How I can use this variable into <a href> tag.

2nd idea may be to use PhP but I am unable to do so.

Any suggestions please.

Thanks and regards,

03-16-2009, 03:18 AM
Perhaps this:

<select onchange="document.getElementById('myLink').href = this.options[this.options.selectedIndex].value">
<option value="http://www.google.com/" selected>Google</option>
<option value="http://www.yahoo.com/">Yahoo</option>
<option value="http://www.lycos.com/">Lycos</option>
<a id="myLink" href="http://www.google.com/">GO!</a>