0

I have this script which I use to link to other sites, but I want to make another one of these, but if I copy all this, except the Javascript, the script breakes and the selects don't go to the given urls anymore.

How could I make this work, the best possible way, with multiple select forms?

<form name="event_type_selector" method="post" action="#">
<select name="url_list" class="event-type-selector-dropdown" onchange="gotosite()">
    <option value="" selected="selected" disabled="disabled">Vælg venligst...</option>

    <optgroup label="Selection 1:">
    <option value="?value-now1">Value-Now 1</option>
    </optgroup>

    <optgroup label="Selection 2:">
    <option value="?value-now2">Value-Now 2</option>
    </optgroup>

</select>

<script language="javascript">
function gotosite() {
    var URL = document.event_type_selector.url_list.options[document.event_type_selector.url_list.selectedIndex].value; 
    window.location.href = URL;
}
</script>

1 Answer 1

6

Just pass in a reference to the <select> in the onchange event. That way you don't need to reference the SELECT from the global scope:

<select ... onchange="gotosite(this)">

function gotosite(select) {
    window.location.href = select.value;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.