Javascript 验证表+;重新使用
我正在尝试在提交后向表单添加重定向页面 现在,在提交表单后,它会显示一条小短信“谢谢发送”,但我希望它重定向到另一个页面。 是否有方法将重定向函数添加到验证脚本或直接添加到表单中Javascript 验证表+;重新使用,javascript,forms,contact-form,Javascript,Forms,Contact Form,我正在尝试在提交后向表单添加重定向页面 现在,在提交表单后,它会显示一条小短信“谢谢发送”,但我希望它重定向到另一个页面。 是否有方法将重定向函数添加到验证脚本或直接添加到表单中 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="htt
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function validateForm() {
var x=document.forms["myForm"]["FirstName"].value;
if (x==null || x=="")
{
alert("Name is missing");
return false;
}
var y=document.forms["myForm"]["MobilePhone"].value;
if (y==null || y=="") {
alert("Mobile is missing");
return false;
}
var y=document.forms["myForm"]["Email"].value;
if (y==null || y=="") {
alert("Mail is missing");
return false;
}
}
</script>
</head>
<body>
<div id="background">
<div id="Background">
<div id="contact">
<form name="myForm" method="post" accept-charset="UTF-8" action="http://clients.frontask.co.il/12137/Pages/Utilities/WebToLead.aspx?type=form" onsubmit="return validateForm()">
<table border="0">
<tbody>
<tr>
<td>
<input type="text" name="FirstName"/>
</td>
<td style="padding-right: 94px;">
<input type="text" name="AccountName" />
</td>
</tr>
<tr>
<td>
<input type="text" name="MobilePhone"/>
</td>
<td style="padding-right: 94px;">
<input type="text" name="Title" />
</td>
</tr>
<tr>
<td>
<input type="text" name="Email" />
</td>
<td style="padding-right: 94px;padding-top: 11px;">
<select name="Address">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
</td>
</tr>
<tr>
<td style="padding-top:5px;">
<input type="checkbox" name="MailingList" checked="checked"/>
</td>
<td style="padding-right: 94px;padding-top: 11px;">
<input type="submit" value="send" />
</td>
</tr>
</tbody>
</table>
<input type="hidden" name="SystemID" value="2e1a82a2-350f-44fe-b571-0fc344f12fbf" />
<input type="hidden" name="ProcessDefinitionStepID" value="PP60400279_0B8F_41F8_ABCC_15834568F4BE" />
<input type="hidden" name="RedirectTo" value="" />
<input name="enc" type="hidden" value="☠" />
<input type="hidden" name="UpdateExistingDetails" value="false" />
<input type="hidden" name="ContactTypes" value="PM8BA799EF_23FF_4679_8484_D603E2DC8BB0" />
</form>
</div>
</div>
</div>
</body>
</html>
试验
函数validateForm(){
var x=document.forms[“myForm”][“FirstName”].value;
如果(x==null | | x==“”)
{
警报(“名称缺失”);
返回false;
}
var y=document.forms[“myForm”][“MobilePhone”].value;
如果(y==null | | y==“”){
警报(“手机丢失”);
返回false;
}
var y=document.forms[“myForm”][“Email”].value;
如果(y==null | | y==“”){
警报(“邮件丢失”);
返回false;
}
}
1.
2.
3.
4.
5.
6.
提交后,使用下面的代码重定向页面
window.location.href = 'give the url which you want to redirect';
将此添加到validateForm()的末尾
你好,普拉文,谢谢你的回答。我试图在验证表结束前添加代码,但没有任何更改,请告诉我应该将代码放在哪里?@Pavel你能检查一下这把小提琴吗。如果你需要帮助,请告诉我。
alert("thank you for sending");
window.location.href = 'give the url which you want to redirect';