0

I have a simple form with options that I want to redirect to. In the root of my index.html which has the following code. I have two folders in same level as index.html. foo/index.html and bar/index.html. I want to redirect to sub-index.html upon option selection and submit. NOT onchange event.

<form id='selector'>
      <div class='input'>
        <select id="foobarid" name="foobar">
            <option value="foo/index.html">foo</option>
            <option value="bar/index.html">bar</option>
        </select>
      </div>
      <div class='input'><a id="foobarsubmit" href="#">submit</a></div>
    </form>

NOTE: most posts explains using jquery/javascript. I am trying to see if it is possible to avoid using jquery/javascript event handlers.

brain storm
  • 30,124
  • 69
  • 225
  • 393

1 Answers1

1

Just set the href of the submit element to the option value onchange of the select something like

<form id='selector'>
      <div class='input'>
        <select id="foobarid" name="foobar" 
                onchange="document.getElementById('foobarsubmit').href = this.value;">
            <option value="foo/index.html">foo</option>
            <option value="bar/index.html">bar</option>
        </select>
      </div>
      <div class='input'><a id="foobarsubmit" href="#">submit</a></div>
</form>
Musa
  • 96,336
  • 17
  • 118
  • 137