Javascript 复选框与其他字段和输入字段的验证
我是网页设计新手 我有一个联系表格,我想验证该表格。当前的javascript在其他领域运行良好,但我被一个服务领域卡住了 这里我想验证是否至少选择了一个服务,如果选中了“其他”选项,则它旁边的输入字段不应为空 表单的HTML代码(服务字段的一部分)为:Javascript 复选框与其他字段和输入字段的验证,javascript,php,forms,validation,Javascript,Php,Forms,Validation,我是网页设计新手 我有一个联系表格,我想验证该表格。当前的javascript在其他领域运行良好,但我被一个服务领域卡住了 这里我想验证是否至少选择了一个服务,如果选中了“其他”选项,则它旁边的输入字段不应为空 表单的HTML代码(服务字段的一部分)为: <form action="" method="post" name="contactus" id="contactus" onsubmit="return validate_contactus()" autocomplete="off"
<form action="" method="post" name="contactus" id="contactus" onsubmit="return validate_contactus()" autocomplete="off">
<input type="checkbox" name="service[]" id="service[]" value="Complete new set up of Histopathology Laboratory">Complete new set up of Histopathology Laboratory<br>
<input type="checkbox" name="service[]" id="service[]" value="Standardization of Histopath techniques">Standardization of Histopath techniques<br>
<input type="checkbox" name="service[]" id="service[]" value="Training of technical staff">Training of technical staff<br>
<input type="checkbox" name="service[]" id="service[]" value="Trouble shooting in day to day work">Trouble shooting in day to day work<br>
<input type="checkbox" name="service[]" id="service[]" value="Addition of new techniques">Addition of new techniques<br>
<input type="checkbox" name="service[]" id="service[]" value="Hands on training">Hands on training<br>
<input type="checkbox" name="service[]" id="service[]" value="Seminars & Workshops in Histopathology">Seminars & Workshops in Histopathology<br>
<input type="checkbox" name="service[]" id="service[]" value="Preparations of documents for NABL Audits">Preparations of documents for NABL Audits<br>
<input type="checkbox" name="service[]" id="service[]" onclick="enable_text(this.checked)" value="other" >Other
<input type="text" name="other_text" id="other_text" autocomplete="off" ><br>
完成组织病理学实验室的新设置
组织路径技术的标准化
技术人员的培训
日常工作中的故障排除
添加新技术
实践培训
组织病理学研讨会和研讨会
为NABL审核准备文件
另外
我用的javascript是:
var chks = document.contactus.getElementsByName('service[]');
var checkCount = 0;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
checkCount++;
}
}
if (checkCount < 1)
{
alert("Please select at least One.");
return false;
}
if (document.contactus.getElementById("other").checked && document.contactus.getElementsByName('other_text').value ==="") {
alert("More Details About Other Service You..... ");
return false;
}
var chks=document.contactus.getElementsByName('service[]);
var检查计数=0;
对于(变量i=0;i
另外,如何通过PHP代码添加所选服务(如果选中了多个服务)?我正在通过电子邮件发送此联系表。目前我使用的是:
Contact Person Name : <?=$_POST['name']?><br><br>
Email : <?=$_POST['email']?><br><br>
Address : <?=$_POST['address']?><br><br>
Mobile : <?=$_POST['mobile']?><br><br>
Service Needed : <?=$_POST['service']?><br><br>
Message : <br><?=$_POST['message']?>
联系人姓名:电子邮件:
地址:
手机:
所需服务:
信息:
如果不使用jquery标记,为什么要添加它?顺便问一下,你的解决方案怎么不起作用呢?我也使用过php验证…所以即使我没有检查任何服务,表单继续…页面重新加载错误消息“一个或多个字段为空…”(我在php验证中使用了此错误消息),它到底是什么?jquery上的验证?关于香草javascript?在php中?@Ghost我需要JavaScript。其中有两个问题。1) Javascript以验证至少一个选择的复选框,如果选中“其他”以验证输入字段。2) PHP-如何在检查所有服务的情况下发送电子邮件(可能是两个、三个或全部)?