Radio Button Validation u
Posted
by
Sirojan Gnanaretnam
on Stack Overflow
See other posts from Stack Overflow
or by Sirojan Gnanaretnam
Published on 2012-12-11T04:18:52Z
Indexed on
2012/12/11
5:04 UTC
Read the original article
Hit count: 146
I am trying validate the radio button using Javascript . But I couldn't get it. Can any one please help me to fix this Issue. I Have attached My Code Below. Thanks.
<form action="submitAd.php" method="POST" enctype="multipart/form-data" name="packages" onsubmit="return checkForm()">
<div id="plans_pay">
<input type="radio" name="group1" id="r1" value="Office" onchange="click_Pay_Office()" style="float:left;margin-top:20px;font-size:72px;">
<label style="float:left; margin-top:20px;" for="pay_office">At Our Office</label>
<img style="float:left;margin-bottom:10px;" src="images/Pay-at-office.png" />
</div>
<div id="plans_pay">
<input style="float:left;margin-top:20px;font-size:72px;" type="radio" name="group1" id="r2" value="HNB" onchange="click_Pay_Hnb()">
<label style="float:left; margin-top:20px;" for="pay_hnb">At Any HNB Branch</label>
<img style="float:left;margin-bottom:10px;" src="images/HNB.png" />
</div>
</form>
Javascript
function checkForm(){
if( document.packages.pso.checked == false && document.packages.pso1.checked == false && document.packages.ph.checked == false && document.packages.ph2.checked == false && document.packages.ph3.checked == false && document.packages.pl.checked == false && document.packages.p3.checked == false && document.packages.p4.checked == false && document.packages.p5.checked == false && document.packages.p6.checked == false ){
alert('Please Select At Least One Package');
return false;
}
if( document.packages.pso.checked == false && document.packages.pso1.checked == false && document.packages.ph.checked == false && document.packages.ph.checked == false && document.packages.ph2.checked == false && document.packages.ph3.checked == false && document.packages.pl.checked == false && document.packages.p3.checked == false && document.packages.p4.checked == false && document.packages.p5.checked == false && document.packages.p6.checked == false){
alert('Please Select At Least One with the Advertise online option in premium package');
return false;
}
if(document.getElementById('words').value==''){
alert("Please Enter the Texts");
return false;
}
if(document.getElementById('r1').checked==false && document.getElementById('r2').checked==false){
alert("Please Select a Payment Method");
return false;
}
}
© Stack Overflow or respective owner