Help needed dynamically accessing table cell values

Discussion in 'Javascript' started by es330td@gmail.com, Oct 31, 2007.

  1. Guest

    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?
    , Oct 31, 2007
    #1
    1. Advertising

  2. On Oct 31, 9:18 am, "" <> 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.innerText);
    }
    Herbert Blenner, Oct 31, 2007
    #2
    1. Advertising

  3. Guest

    On Oct 31, 10:40 am, Herbert Blenner <> wrote:
    > On Oct 31, 9:18 am, "" <> 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.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.
    , Oct 31, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Walzenbach
    Replies:
    1
    Views:
    820
    Steven Cheng[MSFT]
    Feb 18, 2004
  2. Richard Dixson
    Replies:
    1
    Views:
    496
    Joe Fallon
    May 18, 2004
  3. Richard Dixson
    Replies:
    2
    Views:
    722
    Richard Dixson
    May 18, 2004
  4. Phillip Roncoroni
    Replies:
    14
    Views:
    1,072
    Toby A Inkster
    Apr 5, 2004
  5. nicosk
    Replies:
    3
    Views:
    173
    Thomas 'PointedEars' Lahn
    Apr 14, 2009
Loading...

Share This Page