gpt4 book ai didi

javascript - 如何使调查问卷上的提交按钮起作用

转载 作者:行者123 更新时间:2023-12-03 07:36:47 25 4
gpt4 key购买 nike

我正在制作一份健康调查问卷,但遇到一些问题。主要问题是 else 部分。有人可以告诉我为什么它不起作用并帮助我对其进行排序吗?

我的代码是: 作业4

健康问卷


<body>
<form name="form1">
Please enter the following details: <p>
First Name: <br>
<input type="text" name="txtFirstName"> size="20" maxlength="20"> <p>
Surname: <br>
<input type="text" name="txtSurName"> size="30" maxlength="20"> <p>
Age: <br>
<input type="text" name="txtAge" size="3" maxlength="3"> <p>
Address Line 1: <br>
<input type="text" name="txtAddressline1" size="30" maxlength="30"> <p>
Address Line 2: <br>
<input type="text" name="txtAddressline2" size="30" maxlength="30"> <p>
City: <br>
<input type="text" name="txtCity" size="20" maxlength="20"> <p>
County: <br>
<input type="text" name="txtCounty" size="20" maxlength="20"> <p>
Post Code: <br>
<input type="text" name="txtPostCode" size="10" maxlength="10"> <p>

<input type="submit" value="Check Details" name=validateForm
onclick="validateForm_onclick()">

<script type ="text/javascript">
function validateForm_onclick()
{
var myForm = document.form1;
if(myForm.txtAge.value === "" || myForm.txtFirstName.value === ""||

myForm.txtSurName.value === ""|| myForm.txtAddressline1.value === ""||
myForm.txtAddressline2.value === ""|| myForm.txtCity.value === ""||

myForm.txtCounty.value === ""|| myForm.txtPostCode.value === "")
{
alert("Please complete all of the form");
if(myForm.txtFirstName.value ==="")
{
myForm.txtFirstName.focus();
}
else
{
myForm.txtSurName.focus();
}
else
{
myForm.txtFirstName.focus();
}
else
{
myForm.txtAge.focus();
}
else
{
myForm.txtAddressline1.focus();
}
else
{
myForm.txtAddressline2.focus();
}
else
{
myForm.txtCity.focus();
}
else
{
myForm.txtCounty.focus();
}
else
{
myForm.txtPostCode.focus();
}
}
else
{
alert("Thanks for completing the form " + myForm.txtName.value);
myForm.submit();
}
}
</script
</form>
</body>

我还需要保留名称的大小,但需要对用户隐藏。有人可以给我一些关于如何改变这个的建议吗?

最佳答案

您的表单没有提交按钮。您的代码:

<input type="button" value="Check Details" name=validateForm
onclick="validateForm_onclick()">

更正后的代码:

<input type="submit" value="Check Details" name=validateForm
onclick="validateForm_onclick()">

此外,长长的 else 列表在 JavaScript 中是非法的。

关于javascript - 如何使调查问卷上的提交按钮起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35577912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com