Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Help needed dynamically accessing table cell values

Reply
Thread Tools

Help needed dynamically accessing table cell values

 
 
es330td@gmail.com
Guest
Posts: n/a
 
      10-31-2007
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?

 
Reply With Quote
 
 
 
 
Herbert Blenner
Guest
Posts: n/a
 
      10-31-2007
On Oct 31, 9:18 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> 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[i].innerText);
}

 
Reply With Quote
 
 
 
 
es330td@gmail.com
Guest
Posts: n/a
 
      10-31-2007
On Oct 31, 10:40 am, Herbert Blenner <(E-Mail Removed)> wrote:
> On Oct 31, 9:18 am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
>
>
>
>
> > 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[i].innerText);
> }- Hide quoted text -
>
> - Show quoted text -


This

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

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically changing cell values with Javascript / Ajax nicosk Javascript 3 04-14-2009 08:47 PM
Can you persist table cell values like you do with form field values? Richard Dixson ASP .Net 2 05-18-2004 01:11 PM
Can you persist table cell values like you can do with form field values? Richard Dixson ASP .Net 1 05-18-2004 03:47 AM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
Help needed with MouseOver and MouseOut on table cell. Thank you!!! Daniel Walzenbach ASP .Net 1 02-18-2004 03:10 AM



Advertisments