我有一个包含3个选择题的表单。根据每个问题的选择选项,问题将导致5页(网址)之一。
我在这里搜索了一个类似情况的javascript,但脚本在我的网站中不起作用。
我的表单代码是:
<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>
和我的脚本是
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>
我正在学习javascript。请问,我在剧本中缺少什么?
答案 0 :(得分:0)
我已经让脚本工作了。我在“里程”值中删除了逗号,并将提交按钮替换为type = submit to type = button。也许有一些覆盖提交功能的东西?还将脚本函数从“replace()”更改为“calc()”。不清楚哪个项目直接影响了剧本,但它现在按照我的预期工作。