提交时未清除表单
Form not Cleared on Submit
我在一个网站上工作,在那里我应该在提交时清除注册表。提交时的表单被重定向到一个php脚本,在那里我通过php脚本将表单发送到电子邮件。我不知道我错在哪里,但我无法在提交后清除表格的内容。它成功地检查了空白值,当我提交时,它没有清除控件,我使用的是一个函数clear form,如果我在提交前运行它。。它清除了表单,但没有任何数据发送到脚本。。请帮我进入同一个
这是我的Java scirpt
function verifyEmail(form) {
//alert(frmContact.email.value);
checkEmail = contactform.email.value;
form=contactform;
//alert("Please select an answer.");
if(form.fname.value=='')
{
alert("Name is blank");
form.fname.select();
return false;
}
else if(form.dob.value=='')
{
alert("Date Of Birth is blank");
form.dob.select();
return false;
}
else if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.')))
{
alert("You have entered an invalid email address. Please try again.");
form.email.select();
return false;
}
else if(form.mob.value.search(/'d{3}'-'d{3}'-'d{4}/)==-1)
{
alert("The phone number you entered is not valid.'r'nPlease enter a phone number with the format xxx-xxx-xxxx");
form.mob.select();
return false;
}
else if(form.state.value=='')
{
alert("State is blank");
form.state.select();
return false;
}
else if(form.city.value=='')
{
alert("City is blank");
form.city.select();
return false;
}
else if(form.message.value=='')
{
alert("Message is blank");
form.message.select();
return false;
}
else
{
form.method="post";
form.target="_self";
form.action="reg_contact.php";
form.submit();
form.fname.value='';
form.dob.value='';
form.email.value='';
form.mob.value='';
form.state.value='';
form.city.value='';
form.message.value='';
clearForm();
}
}
//--></script>
<script language="javascript">
function clearForm(form)
{
$(":input", form).each(function()
{
var type = this.type;
var tag1= this.tagName.toLowerCase();
var tag = this.tagName.toLowerCase();
if (type == 'text' || tag=='textarea' )
{
this.value = "";
}
});
};
这是我的表单内容
<form id="contactform" class="form" method="post" name="contactform" onsubmit="return(verifyEmail())" style="height: 499px">
<fieldset>
<div>
<label for="fname" style="width: 216px">Full Name:<span> *</span>
</label><input id="fname" name="fname" type="text"> </div>
<div style="margin-left: 45%; margin-top: -13%;">
<label for="name" style="width: 250px">Date Of Birth:<span> *</span></label><input id="datepicker" name="dob" type="text" />
</div>
<div>
<label style="width: 216px">E-mail:<span>*</span></label><input id="email" name="email" type="text">
</div>
<!--
<div>
<label for="email" >Email: <span>*</span></label>
<input name="email" type="email" id="email" pattern="^[A-Za-z0-9](([_'.'-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)((['.'-]?[a-zA-Z0-9]+)*)'.([A-Za-z]{2,})$" />
</div>
-->
<div style="margin-left: 45%; margin-top: -13%;">
<label accesskey="U" for="name" style="width: 216px">Mobile Number:<span>
*</span></label> <input id="mob" name="mob" type="text" /> </div>
<div>
<label>State:<span> *</span></label>
<input id="state" name="state" type="text"> </div>
<div style="margin-left: 45%; margin-top: -12.5%;">
<label accesskey="U" for="name">City:<span> *</span></label>
<input id="city" name="city" type="text"> </div>
<div>
<label accesskey="U" for="name">Country:<span> *</span></label>
<input id="country" disabled="disabled" name="country" type="text" value="India" />
</div>
<div>
<label>Course:<span> *</span></label>
<select id="cource" name="cource" style="height: 34px; width: 241px">
<option value="Diploma Polytechnic">Diploma - Polytechnic</option>
<option selected="" value="UG-BE">Bachelor Of Engineering (BE)</option>
<option value="UG-B.Tech">Bachelor Of Technology (B.Tech)</option>
<option value="PG-MCA">Master Of Computer Application (MCA)</option>
<option value="PG-ME">Master Of Engineering (ME)</option>
<option value="PG-M.Tech">Master Of Technology (M.Tech)</option>
</select> </div>
<div>
<label accesskey="C" for="comments">Message: <span>*</span></label>
<textarea id="comments" cols="40" name="message" rows="3" spellcheck="true"></textarea>
</div>
</fieldset>
<input id="submit" class="submit" style="height: 36px; width: 90px; margin-top: -0.18%;" type="submit" value=" Send ">
<input id="reset" class="reset" style="height: 36px; width: 90px; margin-left: 5px; margin-top: -0.18%;" type="reset" value=" Reset ">
<div class="clearfix">
</div>
</form>
请告诉我哪里出了问题。。。我知道我把这件简单的事搞砸了。
更改
<form ... onsubmit="return(verifyEmail())" ...>
至
<form ... onsubmit="this.reset(); return verifyEmail();" ...>
或者保留你已经拥有的功能:
function clearForm(form) { // pass a DOM element
form.reset();
}
为表单<form action="" ... >
提供操作
相关文章:
- 如何在使用AngularJS更改下拉值时清除表单中的数据
- 在Chrome中重新加载页面后清除表单输入值
- Angularjs:提交后清除表单无效
- 如何在表单提交后清除输入字段
- 我无法使用 .reset() 清除表单
- 我无法从引导模式中清除表单数据
- 在JSP中成功提交表单后清除表单字段
- IE11在使用JQuery$(..).val(“”)清除具有5个或更多字段的表单时崩溃
- 当我点击提交并尝试检查表单验证时,我的html表单将清除
- 如何正确清除AngularJS控制器输入无效的表单
- 表单验证会不断清除字段
- 如何在提交表单后清除以前的文本字段值而不刷新整个页面
- 如何在我的create.js.erb中重置/清除表单
- 谷歌应用程序将电子邮件表单脚本转换为PDF格式,但希望清除一些单元格
- 如何使用javascript删除项目和清除表单
- 当没有表单名称时,如何在AngularJS中清除表单
- 如何不清除表单jQuery中禁用的输入
- 使用 jQuery 重置/清除表单
- 提交 angularjs 后清除表单
- 提交后清除 PHP 表单