Avatar of aguisa
aguisa
Flag 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++;
    }
});
AJAX

Avatar of undefined
Last Comment
aguisa

8/22/2022 - Mon
leakim971

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

aguisa

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

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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
leakim971

>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
haloexpertsexchange

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
aguisa

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
aguisa

ASKER
I couldn't follow up what you suggested. Thanks anyway.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.