Opeyemi Odedeyi
Opeyemi Odedeyi

Reputation: 770

making a forms dropdown a link?

I created a form and I want the form to behave in a way that when it is filled and submitted it will lead then to a page based on what was selected by them in the dropdown.

<div id="type">
   Drop down one:
   <select id="typefield">
        <option>Option 1</option>
        <option>Option 2</option>
        <option>Option 3</option>
        <option>Option 4</option>
   </select>
</div>

Upvotes: 0

Views: 37

Answers (1)

Jackson
Jackson

Reputation: 3518

Attach an onchange event to the select field and when the user selects a new value, update the form's action attribute to point to the new url.

var form = document.getElementById('myForm');
var select = document.getElementById('mySelect');

select.onchange=function(e){
    form.setAttribute('action', e.target.value);
}

See this jsFiddle

Upvotes: 1

Related Questions