0

I have the below javascript function to go to the selected box value url.

function go(x) {
    alert(x);
    location = x.value;
}

I cannot use getElementById There may be more than 1 select box as the user differs I wrote a php to print all the selectbox inside a form and div

<div class="styled-select">
    <form name="menu">
        <select id=Admission onchange=go(this)>
            <option value=/admission>Add Existing Students</option>
        </select> 
        <select id=Student onchange=go(this)>
            <option value=www.bing.com>Student Details</option>
        </select>
    </form>
</div>

All suggestions are welcome.

1 Answer 1

3

You don't access the value of the element properly. Use this instead:

function go(x) {
    location = x.options[x.selectedIndex].value;
}

You also won't get an onchange event for a <select> with only a single option ever.

Sign up to request clarification or add additional context in comments.

1 Comment

If this was the answer you needed, please mark it as Accepted!

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.