Click to See Complete Forum and Search --> : validation radio buttons and checkboxes


elamvik
11-04-2003, 04:10 AM
Hi, I know there are other threads with partly similar problems, but I haven't been able to find exactly what I need.

I found a tutorial about form validation:
http://javascript.internet.com/forms/val-external-js.html

That script validates only text fields, and I need to add validation for required radio buttons and checkboxes as well. Here's an example on what I need:

- 3 radio buttons (all unchecked), one must be checked by user
- 3 checkboxes (all unchecked), minimum one must be checked by user

I have given the radio buttons the same name, the same goes for the checkboxes, but the script doesn't like it very much.

If somebody could help me out I would be very grateful!

Thanks,
Ela

elamvik
11-04-2003, 09:49 AM
some more info, if that can help somebody to help me:

The validation has to be in an external script (chkForms.js), since many of our forms will need the same. The validation I have tried you'll find when clicking the link in my last post.

This is in my form:
<script language="JavaScript" src="/Library/chkForms.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function init() {
define('text1', 'string', 'Marke / Typ');
define('text2', 'string', 'Hubraum');
define('text3', 'string', 'Anzahl Plätze');
define('text4', 'string', 'Kantonskennzeichen Textfeld');
define('radio1', 'radio', 'Anrede des Antragstellers');
}
// End -->
</script>

<BODY OnLoad="init()">

Here are my radio buttons:
<input type="radio" name="radio1" value="Herr"> Herr
<input type="radio" name="radio1" value="Frau"> Frau
<input type="radio" name="radio1" value="Firma"> Firma

Submit button:
<input type=submit name=submit onClick="validate();return returnVal;" value="Test fields">

The text validation runs fine if I remove the radio check. How can I add the radio validation properly?

Many thanks in advance!
Ela