PDA

View Full Version : I want to validate a form only if certain conditions are met



svennie12
05-08-2008, 08:53 PM
Hi all,

Wondering if you can direct me on how to start this. This is an event registration form. If someone clicks Yes I will attend (radio button), then they should proceed to fill out the form (and this form should be validated onsubmit). The other option is for them to click No (radio button), I will not attend. If they choose this, then they should be able to submit without having to complete the form.

I'm not sure where to begin. I have all the proper validation code for a basic form. I keep thinking I should be putting the validation function inside an if statement (i.e. if the Yes radio button is checked, validate the form, otherwise don't). But I can't get it to work and I don't think this is the proper way anyways.

Your thoughts are appreciated!

djr33
05-09-2008, 12:22 AM
An if statement is in fact how you'll want to do this. But you'll need to post something for us to work with in order for us to help-- your code, or a link to the page, etc.

svennie12
05-09-2008, 03:01 AM
Cool, ok here is a snippet:

<script type=text/javascript>
if ( document.getElementById('radio1').checked == true

{
function validate_form ()
{
if ( document.CeMAT.vorname.value == "" ){
alert ( "Geben Sie bitte Ihren Vornamen ein" );
document.CeMAT.vorname.focus();
document.CeMAT.vorname.select();
return false;
}
if ( document.CeMAT.nachname.value == "" ){
alert ( "Geben Sie bitte Ihren Nachnamen ein" );
document.CeMAT.nachname.focus();
document.CeMAT.nachname.select();
return false;
}
if ( document.CeMAT.firma.value == "" ){
alert ( "Geben Sie bitte Ihren Firmenname ein" );
document.CeMAT.firma.focus();
document.CeMAT.firma.select();
return false;

}
}
return true;
}