Hi,

I have the following bit of script which I'm hoping to adapt on my site.

Currently it checks one form submission and returns the data to my php page.

PHP Code:
$(document).ready(function(){
    $(
"#submit").click(function(){                                          
        $(
".error").hide();
        var 
hasError false;
        var 
emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            
        var 
emailFromVal = $("#emailFrom").val();
        if(
emailFromVal == '') {
            $(
"#emailFrom").after('<span class="error">You forgot to enter the email address to send from.</span>');
            
hasError true;
        } else if(!
emailReg.test(emailFromVal)) {    
            $(
"#emailFrom").after('<span class="error">Enter a valid email address to send from.</span>');
            
hasError true;
        }
        
        var 
subjectVal = $("#subject").val();
        if(
subjectVal == '') {
            $(
"#subject").after('<span class="error">You forgot to enter the subject.</span>');
            
hasError true;
        }
        
        var 
messageVal = $("#message").val();
        if(
messageVal == '') {
            $(
"#message").after('<span class="error">You forgot to enter the message.</span>');
            
hasError true;
        }
        
        
        
        
        
        
        
        if(
hasError == false) {
            $(
this).hide();
            $(
"#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');
            
            $.
post("/wp-content/uploads/2008/01/sendemail.php",
                   { 
emailToemailToValemailFromemailFromValsubjectsubjectValmessagemessageVal },
                       function(
data){
                        $(
"#sendEmail").slideUp("normal", function() {                   
                            
                            $(
"#sendEmail").before('<h1>Success</h1><p>Your email was sent.</p>');                                            
                        });
                       }
                 );
        }
        
        return 
false;
    });                           
}); 
However, my form has three radio buttons(id = ctype) and I basically want to set it up so if:
- ctype equals 1 then it runs the email validation check.
- ctype equals 2 then it runs the subject check.
- ctype equals 3, it runs the message check.

How do I go about doing this?


Many thanks for any pointers.