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
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Problem with Form Validation script

    Hi

    I am creating a form with two text boxes where the user can enter two sizes. The maximum size allowable is 1220 X 915mm or 915 X 1220mm.
    I am using a form validation script from the jQuery website which works well. the two text fields include "data-between-numeric="80 1220"" which sets the minimum number allowed to 80 and the max number to 1220.

    I am using a jQuery change() to change the value of the data-between-numeric attribute from "80 1220" to "80 915" based on the value entered into the other text box, i.e. if the user enters 916 or more in the first text box, the data-between-numeric for the second box changes to "80 915"

    This all works correctly. However when the form validation script is run is doesn't acknowledge the updated data-between-numeric values even though I can see they have changed by viewing the source. Everything seems to work correctly the first time but it looks like I need the form validation to recheck to data-between-numeric values everytime it is run.

    Hopefully I have explained this as much as I can.

    Here is my code so far


    Code:
    <form id="sizeInput">
      <div class="control-group">
        <div class="controls">
          <input class="formfield" id="image_width" name="up_img_w" size="4" data-int data-between-numeric="80 1220" title="Width"  value="80" type="text" />
          mm </div>
      </div>
      <div class="control-group">
        <div class="controls">
          <input class="formfield" id="image_height" name="up_img_h" size="4" data-int data-between-numeric="80 1220" title="Height" value="80" type="text" />
          mm </div>
      </div>
    </form>
    <script>
    
    		// Validate on form submission
    		
    		jQuery('#image_width, #image_height').keyup(function() {	
    			var image_width = jQuery("#image_width").val();
    		    var image_height = jQuery("#image_height").val();
    				if (image_height >=  916) {
    			
    					jQuery("#image_width").attr('data-between-numeric','80 915');
    				 jQuery("#image_height").attr('data-between-numeric','80 1220');}
    				
    	
    				 else if (image_width  >=  916) {
    				 		jQuery("#image_height").attr('data-between-numeric','80 915');
    					jQuery("#image_width").attr('data-between-numeric','80 1220');}
    				 
    
    				else {jQuery("#image_width, #image_height").attr('data-between-numeric','80 1220');}
    				
    		
    		});
    		
    		
    			
    		jQuery('#sizeInput').change(function(e) {	
    		e.preventDefault();
    			jQuery(this).formvalidate({
    				failureMessages: true,
    				messageFailureClass: 'label label-important',				
    				onFailure: function(O) {
    				jQuery(".noProgress").show();
    				jQuery("#selectMountStyle").hide();
    
    				},
    				onSuccess: function(O) {
    				jQuery(".noProgress").hide();
    				jQuery("#selectMountStyle").show();
    
    				}
    
    			});
    		});
    		
    </script>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,180
    Thanks
    23
    Thanked 603 Times in 602 Posts
    I have run the code you have posted. The first function runs the second "jQuery('#sizeInput').change(function(e) {" never does. Something is missing.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts
    sorry, you will need the formvalidate code to test.

    http://www.vmichnowicz.com/examples/...ormvalidate.js


  •  

    Posting Permissions

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