Note that there are some explanatory texts on larger screens.

plurals
  1. POform with two variables submitted and redirected to a web page
    primarykey
    data
    text
    <p>I am trying to create a form with two drop down menus which users need to choose from, which they they will submit and depending on the selection from the two drop down menus they will be redirected to a web page, I have managed to make something work with a if statement but I'm trying to use a more cleaner way of doing it. I tried to use a case statement but cant get it to work.</p> <p>Please bare in mind I am still green to JavaScript</p> <p>Here is what I have done till now:</p> <pre><code> &lt;form&gt; &lt;p&gt; Type of Terrain: &lt;/p&gt; &lt;select id="type"&gt; &lt;option value="0" id="Select"&gt;Select&lt;/option&gt; &lt;option value="1" id="Street_Park"&gt;Street/Park&lt;/option&gt; &lt;option value="2" id="Dirt"&gt;Dirt&lt;/option&gt; &lt;option value="3" id="Racing"&gt;Racing&lt;/option&gt; &lt;/select&gt; &lt;p&gt;Body Height&lt;/p&gt; &lt;select id="height"&gt; &lt;option value="0" id="Select"&gt;Select&lt;/option&gt; &lt;option value="1" id="5ft"&gt;4ft&lt;/option&gt; &lt;option value="2" id="5.5ft"&gt;4.25ft&lt;/option&gt; &lt;option value="3" id="5.5ft"&gt;4.50ft&lt;/option&gt; &lt;option value="4" id="6ft"&gt;4.75ft&lt;/option&gt; &lt;option value="5" id="5ft"&gt;5ft&lt;/option&gt; &lt;option value="6" id="5.5ft"&gt;5.25ft&lt;/option&gt; &lt;option value="7" id="6ft"&gt;5.50ft&lt;/option&gt; &lt;option value="8" id="5ft"&gt;5.75ft&lt;/option&gt; &lt;option value="9" id="5.5ft"&gt;6ft&lt;/option&gt; &lt;option value="10" id="6ft"&gt;6.25ft&lt;/option&gt; &lt;/select&gt; &lt;br /&gt;&lt;br /&gt; &lt;input onclick="goToPage();" type="button" value="Submit" /&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; function goToPage() { var type = document.getElementById("type").value; var height = document.getElementById("height").value; switch ("type" &amp;&amp; "height"){ case type == 1 &amp;&amp; height == 1 : window.location = "http://www.maltabmx.com/About.html" Break; case type == 1 &amp;&amp; height == 2 : window.location = "http://www.maltabmx.com/Footage.html" Break; } } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload