I am trying to prevent a form from submitting if the length of input text field with the id “num” is less than 10. However it doesn’t seem to be working.
$('#num').val().length;
See my code here in fiddler. Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re setting your
vvariable when the page is loaded. At this time, the string length is 0. You need to move that code one line down, beneathOtherwise, the
vvariable is never updated, which is why you’re always getting 0.Updated fiddle.