Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / October 2007



Tip: Looking for answers? Try searching our database.

Help needed dynamically accessing table cell values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
es330td@gmail.com - 31 Oct 2007 15:18 GMT
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?
Herbert Blenner - 31 Oct 2007 15:40 GMT
On Oct 31, 9:18 am, "es33...@gmail.com" <es33...@gmail.com> 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
[quoted text clipped - 29 lines]
> 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);
 }
es330td@gmail.com - 31 Oct 2007 16:26 GMT
> On Oct 31, 9:18 am, "es33...@gmail.com" <es33...@gmail.com> wrote:
>
[quoted text clipped - 41 lines]
>
> - Show quoted text -

This

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

works.  I wouldn't have gotten that without the original responder's
help.  Thanks.
Doug Miller - 31 Oct 2007 16:15 GMT
[...]
> function checkvalue(myvar) {
>  var ary,i;
[quoted text clipped - 14 lines]
>property it tells me Object Required.  What is the right way to do
>this?

Have you tried getElementById('td' + i) ?

Signature

Regards,
       Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.