Help needed dynamically accessing table cell values

E

es330td

I have an application that puts a table of values on a page along with
a form whereby the user may add a value. I need to make sure that the
value does not already exist in the table so I want to run a onBlur
function to check the value when they are ready to submit it. The
cells in question are dynamically generated so I do not know before
the page loads how many cells there will be. All cells have an ID
value of TDx, e.g. TD1 or TD14

I tried this code:
<form>
<table><tr><td id="td1">1/2/2007</td><td id="td2">3/14/2007</td></tr></
table>
<input type=text name="myvaluetotest" onBlur="checkvalue(this)">
</form>
<script language=javascript>
function checkvalue(myvar) {
var ary,i;

ary = document.getElementsByTagName("TD")
for(i in ary)
{
alert(i + ' ' + document.getElementById('td1').innerText);
}
}
</script>

When I run this onBlur it will run through the loop and pop up an
alert box with TD1 1/2/2007 and then one with TD2 3/14/2007. As a
result I know that the ary = assignment is working.

However, if I try to substitute i for the 'td1' in the getElementById
property it tells me Object Required. What is the right way to do
this?
 
H

Herbert Blenner

I have an application that puts a table of values on a page along with
a form whereby the user may add a value. I need to make sure that the
value does not already exist in the table so I want to run a onBlur
function to check the value when they are ready to submit it. The
cells in question are dynamically generated so I do not know before
the page loads how many cells there will be. All cells have an ID
value of TDx, e.g. TD1 or TD14

I tried this code:
<form>
<table><tr><td id="td1">1/2/2007</td><td id="td2">3/14/2007</td></tr></
table>
<input type=text name="myvaluetotest" onBlur="checkvalue(this)">
</form>
<script language=javascript>
function checkvalue(myvar) {
var ary,i;

ary = document.getElementsByTagName("TD")
for(i in ary)
{
alert(i + ' ' + document.getElementById('td1').innerText);
}
}
</script>

When I run this onBlur it will run through the loop and pop up an
alert box with TD1 1/2/2007 and then one with TD2 3/14/2007. As a
result I know that the ary = assignment is working.

However, if I try to substitute i for the 'td1' in the getElementById
property it tells me Object Required. What is the right way to do
this?

function checkvalue(myvar) {
var ary,i;
ary = document.getElementsByTagName("TD")
for(i in ary)
{
alert(i + ' ' + document.getElementById(ary.innerText);
}
 
E

es330td

I have an application that puts a table of values on a page along with
a form whereby the user may add a value. I need to make sure that the
value does not already exist in the table so I want to run a onBlur
function to check the value when they are ready to submit it. The
cells in question are dynamically generated so I do not know before
the page loads how many cells there will be. All cells have an ID
value of TDx, e.g. TD1 or TD14
I tried this code:
<form>
<table><tr><td id="td1">1/2/2007</td><td id="td2">3/14/2007</td></tr></
table>
<input type=text name="myvaluetotest" onBlur="checkvalue(this)">
</form>
<script language=javascript>
function checkvalue(myvar) {
var ary,i;
ary = document.getElementsByTagName("TD")
for(i in ary)
{
alert(i + ' ' + document.getElementById('td1').innerText);
}
}
</script>
When I run this onBlur it will run through the loop and pop up an
alert box with TD1 1/2/2007 and then one with TD2 3/14/2007. As a
result I know that the ary = assignment is working.
However, if I try to substitute i for the 'td1' in the getElementById
property it tells me Object Required. What is the right way to do
this?

function checkvalue(myvar) {
var ary,i;
ary = document.getElementsByTagName("TD")
for(i in ary)
{
alert(i + ' ' + document.getElementById(ary.innerText);
}- Hide quoted text -

- Show quoted text -


This

alert(i + ' ' + ary.innerText);

works. I wouldn't have gotten that without the original responder's
help. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top