在我想要的代码中,如果我检查了que3那么它应该填写que3&下面的所有下面的数据将值发布到.php页面。但是在代码中我填写了qeu3&的所有细节。单击提交按钮,然后将表单值发布到下一页,而不是在que4中显示错误。我真的不知道代码中发生了什么。为什么它在que4中出错。我不想要它。任何人都可以帮我解决。
function validate(){
document.getElementById('msgerr').innerHTML='';
document.getElementById('error5').innerHTML='';
document.getElementById('error6').innerHTML='';
document.getElementById('error61').innerHTML='';
document.getElementById('error7').innerHTML='';
document.getElementById('error8').innerHTML='';
if(!(document.getElementById('ques3').checked) && !(document.getElementById('ques4').checked)) {
document.getElementById('msgerr').innerHTML="select any one of them";
return false;
}
if(!(document.getElementById('ques3').checked) && !(document.getElementById('ques4').checked)) {
document.getElementById('msgerr').innerHTML="select any one of them";
return false;
}
<!-- for 3rd main que -->
if(document.getElementById('ques3').checked)
{
var a = document.getElementById("list4");
var option4 = a.options[a.selectedIndex].value;
var b = document.getElementById("list5");
var option5 = b.options[b.selectedIndex].value;
var c = document.getElementById("list6");
var option6 = c.options[c.selectedIndex].value;
if(document.form.cloudapp.value == ''){
document.getElementById('error5').innerHTML="fill all values";
document.form.cloudapp.focus();
return false;
}
else if(option4=="none1"){
document.getElementById("error5").innerHTML="Please select list1";
document.form.list4.focus();
return false;
}
else if(option5=="none2"){
document.getElementById("error5").innerHTML="Please select list2";
document.form.list5.focus();
return false;
}
else if(option6=="none3"){
document.getElementById("error5").innerHTML="Please select list3";
document.form.list6.focus();
return false;
}
else if(!(document.getElementById('thirdsubque11').checked)){
document.getElementById("error6").innerHTML="Please select hosting type";
document.form.thirdsubque11.focus();
return false;
}
else if(!(document.getElementById('thirdsubque22').checked)){
document.getElementById("error61").innerHTML="Please select hosting type";
document.form.thirdsubque22.focus();
return false;
}
else if(document.form.page1.value == ''){
document.getElementById('error61').innerHTML="fill all values";
document.form.page1.focus();
return false;
}
else if(!(document.getElementById('azure').checked)){
document.getElementById("error6").innerHTML="Please select hosting type";
document.form.azure.focus();
return false;
}
else if(!(document.getElementById('rackspace').checked)){
document.getElementById("error6").innerHTML="Please select hosting type";
document.form.rackspace.focus();
return false;
}
else if(!(document.getElementById('cloudho').checked)){
document.getElementById("error6").innerHTML="Please select hosting type";
document.form.cloudho.focus();
return false;
}
else if(document.form.cludhost.value == ''){
document.getElementById('error6').innerHTML="fill all values";
document.form.cludhost.focus();
return false;
}
}
<!-- over -->
<!-- for 4th main que -->
if((document.getElementById('ques4').checked) && !(document.getElementById('fourthsubque101').checked) && !(document.getElementById('external').checked)){
document.getElementById('error7').innerHTML="select any one of them";
document.form.fourthsubque101.focus();
return false;
}
if(if((document.getElementById('ques4').checked)){
if(!(document.getElementById('extweb1').checked) &&
!(document.getElementById('social1').checked) &&
!(document.getElementById('payment').checked))
{
document.getElementById('error8').innerHTML="select below
values";
document.form.extweb1.focus();
return false;
}
}
<!-- over -->
return true;
}
div{
color:red;}
<html>
<body>
<form name="form" method="post" action="">
<div id="msgerr"></div>
<table border="1" align="left" cellpadding="1" cellspacing="1">
<!-- 3rd question -->
<tr>
<td style="padding :0;"><input type="checkbox" name="a[]" value="que3" id="ques3" onClick="thirdque();thirdqueUnchk();" />que3</td>
<td></td>
<td><div id="error5"></div></td>
</tr>
<tr id="thiredsubque1">
<td></td>
<td style="padding:0;">Total number of Cloud Apps to be tested</td>
<td style="padding:0;"><input type="text" size="30" id="cloudapp" name="cloudapp" placeholder="number of Cloud Apps to be tested" /></td>
</tr>
<tr id="thiredsubque2">
<td></td>
<td style="padding:0;">Server side programming language</td>
<td style="padding:0;"><select style="width:70%;height:22px;" id="list4" name="cloudserverlang[]">
<option value="none1" selected>None</option>
<option value="31">php</option>
<option value="32">Dot Net</option></select></td>
</tr>
<tr id="thiredsubque3">
<td></td>
<td style="padding:0;">Browser side programming language</td>
<td style="padding:0;"><select style="width: 70%;height: 22px;" id="list5" name="cloudbrowselang[]">
<option value="none2" selected>None</option>
<option value="41">php</option>
<option value="42">Dot Net</option></select></td>
</tr>
<tr id="thiredsubque4">
<td></td>
<td style="padding:0;">Backend Database</td>
<td style="padding:0;"><select style="width: 70%;height: 22px;" id="list6" name="clouddblang[]">
<option value="none3" selected>None</option>
<option value="51">php</option>
<option value="52">Dot Net</option></select></td>
</tr>
<tr id="thiredsubque5">
<td></td>
<td><input type="checkbox" id="thirdsubque11" name="amazon[]" value="Amazon Cloud Hosting" onClick="thirdsubque1();thirdsubque1Unchk()" />Amazon Cloud Hosting</td>
<td><div id="error6"></div></td>
</tr>
<tr id="thiredsubque51">
<td></td>
<td> <input type="checkbox" value="Third party framework used" name="thirdframe[]" id="thirdsubque22" onClick="thirdsubque2();thirdsubque2Unchk()"/>Third party framework used</td>
<td><div id="error61"></div></td>
</tr>
<tr id="thiredsubque511">
<td></td>
<td> Number of pages</td>
<td><input type="text" name="pages2" placeholder="Number of pages" id="page1"/></td>
</tr>
<tr id="thiredsubque6">
<td></td>
<td><input type="checkbox" name="azure[]" id="azure" value="Microsoft Azure Cloud Hosting" />Microsoft Azure Cloud Hosting</td>
<td></td>
</tr>
<tr id="thiredsubque7">
<td></td>
<td><input type="checkbox" name="rackspace[]" id="rackspace" value="Rackspace Cloud Hosting"/>Rackspace Cloud Hosting</td>
<td></td>
</tr>
<tr id="thiredsubque8">
<td></td>
<td><input type="checkbox" name="cloudho[]" id="cloudho" onClick="thirdsubque3();thirdsubque3Unchk()" value="Other cloud hosting"/>Other cloud hosting</td>
<td><input type="text" id="cludhost" placeholder="Other cloud hosting" name="othrcloud" /></td>
</tr>
<!-- 4th question -->
<tr>
<td style="padding:0;"><input type="checkbox" value="que4" name="a[]" id="ques4" onClick="fourthque();fourthqueUnchk();" />que4</td>
<td></td>
<td><div id="error7"></div></td>
</tr>
<tr id="fourthsubque41">
<td></td>
<td><input type="checkbox" name="select41[]" value="Android App" id="fourthsubque101" onClick="fourthsubque11();fourthsubque11Unchk()" />Android App</td>
<td><div id="error8"></div></td>
</tr>
<tr id="fourthsubque411">
<td></td>
<td> <input type="checkbox" name="extweb[]" id="extweb1" value="Calls any external web services"/>Calls any external web services</td>
<td></td>
</tr>
<tr id="fourthsubque412">
<td></td>
<td> <input type="checkbox" name="socialapp[]" id="social1" value="Uses any social media app internally" />Uses any social media app internally</td>
<td></td>
</tr>
<tr id="fourthsubque413">
<td></td>
<td> <input type="checkbox" name="payment[]" id="payment" value="Performs payment transactions"/>Performs payment transactions</td>
<td></td>
</tr>
<tr id="fourthsubque42">
<td></td>
<td><input type="checkbox" name="iOSapp[]" value="iOS App" id="external" onClick="fifthque()" />iOS App</td>
<td></td>
</tr>
<tr>
<td></td>
<td><input type="submit" onClick="return validate()" name="submit" value="Submit" /></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:0)
如果在检查ques4的内部复选框之前检查了ques4,则需要添加。放一个if条件,如:
替换
if(if((document.getElementById('ques4').checked)){
if(!(document.getElementById('extweb1').checked) &&
!(document.getElementById('social1').checked) &&
!(document.getElementById('payment').checked))
{
document.getElementById('error8').innerHTML="select below
values";
document.form.extweb1.focus();
return false;
}
}
与
if(document.getElementById('ques4').checked){
if(!(document.getElementById('extweb1').checked) &&
!(document.getElementById('social1').checked) &&
!(document.getElementById('payment').checked))
{
document.getElementById('error8').innerHTML="select below
values";
document.form.extweb1.focus();
return false;
}
}
答案 1 :(得分:0)
您的javascript代码错误
您的以下代码检查了问题3的条件
if(!(document.getElementById('extweb1').checked) && ! (document.getElementById('social1').checked) && !(document.getElementById('payment').checked)){
document.getElementById('error8').innerHTML="select below values";
document.form.extweb1.focus();
return false;
}
只有在选择了que4
如果条件,上面的代码段必须在下面
if((document.getElementById('ques4').checked) && !(document.getElementById('fourthsubque101').checked) && !(document.getElementById('external').checked)){
}