Java Script Form Validation: Radio buttons, Check box, Drop downs and conditional validation
Posted on 2007-11-19
I posted a question on validating my form and got the following which works the way I want, thanks. I know need to know if I have a radio button group, (Field 2) a check box selection (Field 3) or a drop down (Field 4)... how do I validate that they are not empty.
The second part is that I have a couple of fields that needs to be validated base on the following:
Field 1a - If it is not empty, then Field 1b needs a value as well and not empty.
function validate_form ()
var errors=new Array();
var f = document.getElementById("KMKW_1_Health");
if (f.First_Name.value =="")
errors.push("Given First Name");
if (f.Preferred_First_Name.value =="")
errors.push("Preferred First Name");
if (f.Last_Name.value =="")
alert("Please fill in the following: \n\n"+errors.join("\n"));