<form id="form2" name="form2" action="">
<div class="form_colour" id="formcolour"><img src="../Images/red_car.jpg" alt="" width="370" height="124" />This car is
<label for="textarea"></label>
<input name="text_1" type="text" class="form_colour" id="text_1" />
</div>
<p> </p>
<p><img src="../Images/green_car.jpg" width="370" height="124" />This car is
<input name="text_2" type="text" class="form_colour" id="text_2" />
</p>
<p>
<img src="../Images/Yellow_car.jpg" width="370" height="124" />This car is
<input name="text_3" type="text" class="form_colour" id="text_3" maxlength="8" />
</p>
<p>
<input name="confirm" type="button" class="form_colour" id="confirm" value="Confirm" />
</p>
</form>
我目前有以下代码用于其中包含 3 个文本字段的表单(表单代码在此上方,Javascript 代码在此文本下方)。
我的目标是基于文本值的输入,用户将收到一条消息并留在页面上,或者如果它们是正确的,则收到一条消息并转到另一个页面。我以前为下拉列表做过这个。我所做的只是将变量从下拉列表名称更改为文本字段名称。现在当我运行它时,什么也没有发生,我需要做更多的事情吗???
</script>
<script type="text/javascript">
function checkValues() { // this line must be within the script tags
var a = document.form2.text_1.value;
var b = document.form2.text_2.value;
var c = document.form2.text_3.value;
if (a == "red" && b == "green" && c == "yellow"){
alert ("Correct you have won press OK for your Reward!")
window.location.href = "Reward.html"; // redirect to new page
}
else {
alert ("Not right Please try again!");
window.location.href = "Money_Match.html";
}
}
</script>
</script>