Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
jQuery val or javascript changing value, validate the field even if the value don't match with the Validation Properties

Element Example:

<textarea class="form-control" id="presentation" required="" minlength="10" maxlength="300"></textarea>

If manually, insert any text, the validation is set to Valid if the length is between 10 and 300 chars.

Example: if i manually write "Hello" on the field and run:

$('#presentation')[0].validity.valid
/*will return "false" as expected*/

but if i use any of this way to change the value of the field:

 $('#presentation').prop('value','hell')
//or
 $('#presentation').val('hell')
//or
 $('#presentation')[0].value='hello'

It will cause:

$('#presentation')[0].validity.valid
/*will return "true" and will cause a validation problem*/

it set the field to valid, and the only way to revalidate is to change the value in the field, manually. this will cause that invalid data could be submitted in the form this field will not be checked.

This is happening in Chrome, firefox, edge and opera.

do you know if there's anyway to force the field to validate his value?

here a fiddler with this problem: https://jsfiddle.net/rfigueiredo/jnuhfsc7/20/

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!