Click here to Skip to main content
15,567,466 members
Please Sign up or sign in to vote.
1.91/5 (3 votes)
if suppose there are some 'n' number of fields in a form...and for each mandatory TEXTBOX fields I named them with a class "fileds" and error message I want to display in a LABEL which I placed them below the textboxs with "display:none", and given cssClass="Error"....(So that I do not want to use alert box)

I want to use "each" loop and "blur" event in script tags for that i can reduce my validation code.

1 solution

You could use below mentioned function for that.

function SetErrorFields(fields) {
    ErrorFields = fields;
    for (Field in ErrorFields) {
      alert(ErrorFields[Field][0]+" | "+ErrorFields[Field][1]+" | "+$('#'+ErrorFields[Field][0]).val());
      $('#'+ErrorFields[Field][0]).blur({fld: ErrorFields[Field][0], err: ErrorFields[Field][1]}, function(event){


Note : Here I have put alert box.But you can use your error labels instead of.

For a more in-depth explanation on what it does go :[^]

I hope this will help to you.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900