Link to home
Start Free TrialLog in
Avatar of aguisa
aguisaFlag for Costa Rica

asked on

JQUERY function not working

Hi. I have the following code in my app. The thing is that it is not working as expected. I have several input fields that are identified by id = hord1, hord2 ...., hordn. What I want is to validate every one of them on blur.  Thanks.

var nrows = 0;
$(document).ready(function(){
    var xj = 1;
    updaterows();
    while (xj <= nrows){
        $("#hord"+xj).blur(function(){
            alert (xj);
            validarord(xj);
        });
        xj++;
    }
});
Avatar of leakim971
leakim971
Flag of Guadeloupe image

You get what in the alert with the following :
var nrows = 0;
$(document).ready(function(){
    var xj = 1;
    updaterows();
alert( "number of row : " +nrows);
    while (xj <= nrows){
        $("#hord"+xj).blur(function(){
            //alert (xj);
            validarord(xj);
        });
        xj++;
    }
});

Open in new window

Avatar of aguisa

ASKER

Hi, updaterows() updates the value of nrows, which throw 32 at my context. Thanks for the fast response.
if updaterows(); use ajax, you may to use :
http://api.jquery.com/attribute-starts-with-selector/
and :
http://api.jquery.com/live/
$(document).ready(function(){
    var xj = 1;
    updaterows();
    $("input[id^='hord'"]).live("blur", function(){
         alert (xj);
         validarord(xj);
    });
});

Open in new window

>Hi, updaterows() updates the value of nrows, which throw 32 at my context. Thanks for the fast response.

Yes, but you did not answer to my question. Line 5 we placed an alert which should give the number of row. Confirm you get 0
try something like this

$('input:text[id^=hord]').blur(function() {

Open in new window

that should if formed right get you every input field with an id that starts with hord.
ASKER CERTIFIED SOLUTION
Avatar of aguisa
aguisa
Flag of Costa Rica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aguisa

ASKER

I couldn't follow up what you suggested. Thanks anyway.