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

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!

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.

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" );
return false;
if ( document.CeMAT.nachname.value == "" ){
alert ( "Geben Sie bitte Ihren Nachnamen ein" );
return false;
if ( document.CeMAT.firma.value == "" ){
alert ( "Geben Sie bitte Ihren Firmenname ein" );
return false;

return true;