1

Say I have:

<form>
 <select>
   <option value="page1.html">Page 1</option>
   <option value="page2.html">Page 2</option>
  </select>
 <input type="submit" value="Submit">
</form>

How do I make it so that when I select an option, I click on this Submit button and it goes to the appropriate link that was selected?

2 Answers 2

1

You can try this code.

<form>
 <select onchange="if (this.value) window.location.href=this.value">
   <option value="page1.html">Page 1</option>
   <option value="page2.html">Page 2</option>
  </select>
 <input type="submit" value="Submit">
</form>

Thanks

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

Comments

0

You can use this code:

$(function() {
  $('#frm1').on('submit', function() {
    window.location = $('#sel1').val();
    return false;
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="frm1">
 <select id="sel1"> 
   <option value="page1.html">Page 1</option>
   <option value="page2.html">Page 2</option>
  </select>
 <input type="submit" value="Submit">
</form>

Note that in the example it will not works, since there are no such pages on stackoverflow's server

Comments

Your Answer

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