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>
Dhaval Marthak
17.4k6 gold badges48 silver badges69 bronze badges
asked May 13, 2014 at 13:04

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;
}
answered May 13, 2014 at 13:09
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.