简体   繁体   English

使用表单的多个输入提交到url

[英]submit to url with multiple input of form

I have a form with 3 multiple choice questions. 我有一个包含3个多项选择题的表格。 The questions lead to one of 5 pages (url) depending on the selected choices of each question. 根据每个问题的所选选项,这些问题可进入5页(URL)之一。

I searched here for a javascript that works with a similar situation yet the script doesn't work in my site. 我在这里搜索了可以在类似情况下运行的javascript,但该脚本在我的网站上不起作用。

My form code is: 我的表单代码是:

        <fieldset id="second">

<h3 class="mbot_0"><label>How many miles does your auto have</label>
</h3>
<select id="mileage" data-hint="" name="mileage">
        <option id="m1" selected value="0-15,000">
          0-15,000
        </option>
        <option id="m2" value="15,001-30,000">
          15,001-30,000
        </option>
        <option id="m3" value="30,001-65,000">
          30,001-65,000
        </option>
        <option id="m4" value="65,001-100,000">
          65,001-100,000
        </option>
        <option id="m5" value="100,000+">
          100,000+
        </option></select>

<h3 class="mbot_0"><label>Does your car have a GDI engine?</label></h3>
<select id="gdi" data-hint="" name="gdi">
<option id="" selected value="--">Select one
        </option>
        <option id="" value="yes">Yes</option>
<option id="" value="no">No</option>
</select>

<h3 class="mbot_0"><label>Do you use top-tier fuel when you fill up?</label></h3>
<select id="fuel" >
        <option id="" selected value="--">Select one
        </option>
        <option id="" value="yes">Yes
        </option>
      <option id="" value="no">No
        </option>
      </select>
      <input id="pre_btn1" onclick="prev_step1()" type="button" value="Previous">
      <input type="submit"  id="calculate"
value="Calculate"  onclick="replace()"/>
</fieldset></form>

and My script is 我的脚本是

function replace() {
if (document.getElementById('mileage').value == '0-15,000' && document.getElementById('gdi').value == 'yes' && document.getElementById('fuel').value == 'yes') {
  window.location = 'http://www.arnolfodesign.com/clients/itw_carbonator/outcome01.html';
} else if (document.getElementById('mileage').value == '0-15,000' &&   document.getElementById('gdi').value == 'yes' &&   document.getElementById('fuel').value == 'no') {
  window.location = 'http://www.arnolfodesign.com/clients/itw_carbonator/outcome02.html';
} 
}
</script>

I'm learning javascript as I go. 我正在学习javascript。 Please, what am I missing in the script? 拜托,脚本中我缺少什么?

I've got the script to work. 我有脚本可以工作。 I stripped out the commas in the "mileage" values and also replaced the submission button from type=submit to type=button. 我去除了“里程”值中的逗号,并且还将提交按钮从type = submit替换为type = button。 Maybe there was something overriding the submit function? 也许有一些东西可以覆盖提交功能? Also changed the script function from "replace()" to "calc()". 还将脚本功能从“ replace()”更改为“ calc()”。 Unclear which item directly effected the script but it now works as I expected. 不清楚哪个项目直接影响了脚本,但现在它可以按我的预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM