SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast hotdiggity's Avatar
    Join Date
    Aug 2004
    Location
    Brisbane
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with radio button validation

    Trying to validate two radio buttons in the same group ('paytype'), and further validate fields under each of these buttons depending on which button is checked (in this case, bank account details or credit card details). Have given credit card button the id 'cc' and bank account button the id 'dd' just incase that's required for the solution. Have written the shell of the script here but lack the experience to complete it...


    Code:
    function CheckForm( theForm )
    {
    	var bMissingFields = false;
    	var strFields = "";
    
    //check if direct debit or credit card buttons are checked
    	
      	if(( theForm.paytype[0].checked == false ) &&
      	   ( theForm.paytype[1].checked == false )){
         	
               bMissingFields = true;
      		strFields += "     Payment details: Type of payment \n";
     	}
    
    //if direct debit is selected then check fields are complete
      	if( theForm.paytype[0].checked == true )
      	{
    	if( theForm.bank.value == '' ){
    		bMissingFields = true;
    		strFields += "     Bank account details: Bank\n";
    	}
            //more fields here to validate
            }
    
    
    //if check credit card is selected then check fields are complete
      	if( theForm.paytype[1].checked == true )
      	{
    	if( theForm.cctype.value == '' ){
    		bMissingFields = true;
    		strFields += "     Credit card details: Card Type\n";
    	}
            //more fields here to validate
            }
    
            if( bMissingFields ) {
    		alert( "We're sorry, but you must complete the following field(s) before continuing:\n" + strFields );
    		return false;
    	}
    	return true;
    }

  2. #2
    SitePoint Enthusiast hotdiggity's Avatar
    Join Date
    Aug 2004
    Location
    Brisbane
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't worry, the above works. I had an incorrect form field name elsewhere in the original script that was causing the problem..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •