/    Sign up×
Community /Pin to ProfileBookmark

Validate Multiple Rows

I have a a web page where a user adds additional rows. Once the user adds the additional rows, I would like to validate each row to ensure “firstName” is added. I can get the first row to validate, but not the added rows. I used the following javascript:

function addRow()
{
var row = document.getElementById (‘tab’).getElementsByTagName(‘tr’)[0];
var newRow = row.cloneNode(true);
var i = row.parentNode.children.length;
newRow.children(0).children(0).name = “firstName_” + i;
newRow.children(1).children(0).name = “lastName_
” + i;
row.parentNode.appendChild(newRow);
}

function valRows(){
if (!document.getElementsByTagName || !document.createTextNode) return;
var rows = document.getElementById(‘tab’).getElementsByTagName(‘tbody’)[0].getElementsByTagName(‘tr’);
for (i=0;i<= rows.length;i++){
var frm = document.forms[“form2”];
if (frm[‘firstName_’ + i].value == “”)
alert(‘Enter First Name’);
}
return rows;
}

ANY HELP WOULD BE APPRECIATED!

losssoc

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @losssoc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...