Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    50
    Thanks
    6
    Thanked 0 Times in 0 Posts

    JQuery Validation

    Hi everyone i'm currently working on creating a validation via Jquery I stuck on my validation.... Each time i submit it does not do the validation for my dropdown (#country) and checkbox (agree) can someone show me the proper method of doing a validation for checkbox and drop down. A example would be great. :-)

    JS
    Code:
    jQuery(document).ready(function() {	
     	$('#regform').submit(function(){
     		$.ajax({
     			url: $(this).attr('action'),
     			type: 'POST',
     			data: $(this).serialize(),
    			dataType: 'json',
     			success: function(respond) {
     				if (respond.result == 'false') {
     					$('#feedback').html(respond.errors);	
    				}
    				
    					if($('#agree:checked').val()==undefined)	{
    						$('#return').html('Please agree to the terms and conditions to register');
    						
    						if($('#country').val()=="")	{
    						$('#returncountry').html('Please select a country');
    					}
    					}
    					
    					
    	
    				else {
    					window.location = 'http://localhost/code/index.php/user/nextpg';
    					//$('please agree to the terms and conditions').appendTo('#feedback')
    				}
     			}
     		});
     		return false;
     	});
    });

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    Hi,

    I don't think (?) you can use .val() to check if a checkbox is checked.

    Try with something like : $('#agree').is(':checked');
    Chuck Norris counted to infinity.
    Twice.

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    50
    Thanks
    6
    Thanked 0 Times in 0 Posts
    nah, that works fine when i process it individually. my biggest issue is validation.

    When i have a validation error(on the client side) i show the error but say after i seen that error and fixed that error…resubmit.. that error message will still be there( this is in a event where there also another error on a different validation) so the page does not redirect. I was told by a friend to use the else if statement but i'm confused on how to process that with the code i have currently.

    Code:
    jQuery(document).ready(function() {	
     	$('#regform').submit(function(){
     		$.ajax({
     			url: $(this).attr('action'),
     			type: 'POST',
     			data: $(this).serialize(),
    			dataType: 'json',
     			success: function(respond) {
     				if (respond.result == 'false') {
     					$('#feedback').html(respond.errors);
    					
    				} else{
    					$('#feedback').html('');
    				}
    				
    				if ($('#agree:checked').val()==undefined)	{
    						$('#return').html('Please agree to the terms and conditions to register');	
    						
    					}else {
    						$('#return').html('');
    					}
    					
    					
    			    if ($('#country').val()=="")	{
    						$('#returncountry').html('Please select a country');
    				 }else{
    					 $('#returncountry').html('');
    					 window.location = 'http://localhost/code/index.php/user/nextpg';
    				 }
    	
    				//if( (respond.result!=='false') && ($('#agree:checked').val()!==undefined))  && ($('#country').val()!="")) ) {
    					
    					//$('please agree to the terms and conditions').appendTo('#feedback')
    				//}
     			}
     		});
     		return false;
     	});
    });


  •  

    Posting Permissions

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