0
Checkbox validation using JavaScript
How do I validate at least one checkbox being checked using JavaScript ?
7 odpowiedzi
0
Have you written your code because without it, it is arduous to get plsss share your code here.
0
Jay Matthews Welcome newcomer, here the code you asked for.
Next time please try it your own first, share the code if you need help, try to not ask for total solution.
https://code.sololearn.com/W749l3ifPLqb/?ref=app
0
function Validate(theForm){
var empty = " ";
if (theForm.Title.value == "")
empty += "Title\n";
if (theForm.Initials.value== "")
empty += "Initials\n";
if (theForm.Surname.value == "")
empty += "Surname\n";
if (theForm.Email.value == "")
empty += "Email\n";
if (theForm.Address.value == "")
empty += "Address\n";
if (theForm.hobbies.checked == "")
empty += "hobbies\n";
if (theForm.age.value == "")
empty += "age\n";
if (theForm.Select_Payment.value == "")
empty += "Payment Method\n";
if ( empty !=" "){
alert ("You missed the following essential elements\n"
+ empty
+ "Please complete and resubmit");
return false;
}
}
0
<select Name= "col">
<option Value=" select"> Select colour </option>
<option Value=" bl"> Black </option>
<option Value=" GR"> Green </option>
<option Value=" yl"> Yellow </option>
<option Value=" bt">White </option>
<option Value=" re"> Red</option>
<option Value=" br"> Brown </option>
</Select>
0
what are your hobbies? Please choose from the list below: <BR><BR>
<input type="checkbox" name= "hobbies" value="check"> Football <BR>
<input type="checkbox" name= "hobbies" value="check"> Swimming <BR>
<input type="checkbox" name= "hobbies" value="check"> Computer games <BR>
<input type="checkbox" name= "hobbies" value="check"> Movies <BR>
<input type="checkbox" name= "hobbies" value="check"> Driving <BR>
<input type="checkbox" name= "hobbies" value="check"> Basketball
0
I’d like to validate the checkboxes and dropdown list such that if they blank I get a generally alert with the rest of the fields that are not filled.
0
I can validate them separately but I want on error message for all the empty fields.