2

I am trying to validate a form which allows user input and I'm using the jQuery plugin found below.

http://docs.jquery.com/Plugins/Validation/Methods

The details are being held within a back-end database and validating the date/email/text entries has worked fine and isn't causing any problems.

However, every time I try and specify a number/digits format the back-end php file complains about the data being truncated for 'Age' (One of the database fields) and doesn't execute.

Age is set as an integer in the database, with a max length of 3.. What's causing this to break everytime?


My Code -

 jQuery(document).ready(function(){
   jQuery("#custform").validate({
      rules: {
        DateOfOrder: {
            required: true,
            dateISO: true
        }
        Age: {
            required: true,
            digits: true
        }
      }
   });
 });

My Form Element -

  <p>
    <label for="cname">Age</label>
    <input id="Age" name="Age" size="15" class="required" maxlength="3" /><em>*</em>
  </p>
3
  • So the back end php is throwing a warning/error saying that Age is being truncated? Or is this a back end validation message that you made? But the jQuery validation plugin isn't outputting any warning/error for the age, correct? Commented Mar 23, 2012 at 8:59
  • Post some code, no idea what's going wrong if we can't see what you're trying to do Commented Mar 23, 2012 at 9:04
  • 1
    @Andrew Jackman Normally when I hit submit on the form it obviously pops up that fields are required etc. However when I have specified the 'Age' must be number/digits and hit submit it bypasses validation and throws the error saying the value for Age is truncated.. Is this clearer? Commented Mar 23, 2012 at 9:05

1 Answer 1

1

I found your problem! You are missing a comma:

jQuery(document).ready(function(){
 jQuery("#custform").validate({
  rules: {
    DateOfOrder: {
        required: true,
        dateISO: true
    }, // This comma right here
    Age: {
        required: true,
        digits: true
    }
  }
 });
})

Here is a working jsFiddle for it.

The reason why it still checked for required even though your javascript had the error was because you gave it class="required", which is unnecessary because you are setting it to required in the jQuery ready function (but caused this seemingly strange error).

Sign up to request clarification or add additional context in comments.

2 Comments

Wow it's always the most basic errors, thanks for the fresh pair of eyes!
@William231 No problem! I have definitely spent hours on problems like these myself :p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.