Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How can form input value be cleared before validation?

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #41540

    I want to have input fields with a value inside of the field. But, the initial value needs to be cleared prior to validation or the initial field value is submitted.

    [In example](http://codepen.io/joe/pen/meokF “CodePen”) – the first field (Name) validates even if submit is clicked without changing value.

    I’m using jQuery Validate plugin to perform validation.

    Thank you,
    Charlie

    #118680
    __
    Participant

    a better solution is to use the `placeholder` attribute:

    but it you’re looking for compatibility with older browsers, you can simply check the value and make sure it’s different. If you’re using [Validation](http://docs.jquery.com/Plugins/Validation), you can make a custom rule as part of your validation.

    #118708

    Thank you. I think both ideas can work.

    1. Custom Validation Rule: Can a rule be created that would do something like this… IF the field value is “Name*” THEN do NOT validate IF the field value is “just about anything else more than two characters” THEN validate. (Can anyone offer a the jQuery for this?)

    2. In Field Label: Great idea! Just use the LABEL tag and position it with CSS directly over the field so it looks like a field value. Why didn’t I think of that!

    Thank you!
    Charlie

    #118744
    __
    Participant

    > …IF the field value is “Name*” THEN do NOT validate IF the field value is “just about anything else more than two characters” THEN validate. (Can anyone offer a the jQuery for this?)

    I don’t know specifically, but `$.validator.addMethod` allows you to define custom validation functions. Just start with a check against the value. I’m busy at the moment but I’ll take a look when I get a chance.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.