Passing External Javascript variable into HREF

smdion

Limp Gawd
Joined
May 30, 2003
Messages
447
I have a external JavaScript that populates a drop down menu, with a list of classrooms, based on which building is picked.

What I want is a way to take the value of the item that is selected in the populated drop-down menu and use it in a link.

The link would look something like http://mydomain.edu/its/academic/classroom/rooms/*valueofselecteditem*.html
Is this even possible?
 
you need to add an onchange event listener to the dropdown, then change the href attribute of the link you want.

i.e. to the effect of
Code:
<script type="text/javascript">
function updateLink(selectElement) {
    var value = selectElement.options[selectElement.selectedIndex].value;

    if (null != value && "" != value) {
        document.getElementById("mylink").href = "http://whatever.com/" + value + ".html";
    }
}
</script>

...

<select ... onchange="updateLink(this);">
    <option value="page1">Page 1</option>
...
</select>
<a href="#" id="mylink">Click to go to selected page</a>

not tested but should give you an idea
 
Back
Top