user2349515
user2349515

Reputation:

OnBlur validation before button click()

i like to know how to validate a text-field at it instant.when ever we move to another text field with out filling the above text-field we need to get an alert message using on-blur(). using java-script.

Upvotes: 0

Views: 658

Answers (3)

Karl Adler
Karl Adler

Reputation: 16816

If you like to use the html5 form validation take a look at validity property and set html 5 form attributes like required

html5:

<input type="number" required="true"  onfocus="setCustomValidity('Custom Message')" onblur="testit(this)"/>

js:

function testit(e){
    if(e.validity.valid == false){
        alert(e.validationMessage);
    }
}

http://jsfiddle.net/5ANnf/2/

https://developer.mozilla.org/en-US/docs/HTML/Forms_in_HTML (at bottom)

Upvotes: 0

PSR
PSR

Reputation: 40328

You can use onblur() event in javascript

<input type="text" onblur="test('firstTextBox')"/>

function test(value)
{
  if(value == "firstTextBox")  
  alert("This is blur");
  else if ....
  .....
}

Upvotes: 1

Sreekumar P
Sreekumar P

Reputation: 6050

Have look into jQuery Validate plugin and try the below code to work in onblur.

$('#field1, #field2, #field3').blur(function(){
    validator.validate()
});

Upvotes: 0

Related Questions