PDA

View Full Version : How to validate a radio button?


Prof. Snape
11-27-2002, 03:15 AM
Hi there,

I have to provide a "pretty" large form of about 77 fields.

Some of them are radio-buttons (e.g. "Ms | Mrs | Ms | Prof. | Dr.")

I use JavaScript to ensure that most of the fields are filled out:

function validate()
{
var msg;
var msgflag;
var pswdflag;

msgflag = "false";
var pswdflag = "false";

msg="Please enter values for the following fields:\r";

if(document.forms[0].Title.option == ""){
msg+="\rTitle\r";
msgflag="true";
}

if(msgflag == "true"){
msg
alert(msg)
return false;
}
}


In the page's "onLoad" it is activated and works fine - except for those darn radio-buttons.

This means: The radio-button "Title" contains the values mentioned above (Mr, Mrs, Ms, Dr, Prof.) - but how can i check if any of these options has been chosen?

Thanks in advance for any hint or solution.

Prof. Snape
11-27-2002, 05:17 AM
Just for information:
I just solved the prob.

In case anyone here needs to know, here's the correct code:

simply change the "if"-part from "document.forms[0].Title.value" into:

if(document.forms[0].Anrede.checked == false )
{
msg+="\rTitle\r";
msgflag="true";
}