Get data from textbox inside a table - Javascript

This is a discussion on Get data from textbox inside a table - Javascript ; Hello, how can i get data from this table: <table> <tr><td>someText</td></tr> <tr><td> <input name="DataGrid1:_ctl2:textBox" type="text" value="someText" id="DataGrid1__ctl2_textBox" style="width:140px;" /> </td></tr> </table> for the first column I can use: var column1 = table.rows[rowIndex].cells[0].childNodes[0].data; and I get 'someText' how can I get ...

+ Reply to Thread
Results 1 to 4 of 4

Get data from textbox inside a table

  1. Default Get data from textbox inside a table

    Hello,

    how can i get data from this table:
    <table>
    <tr><td>someText</td></tr>
    <tr><td>
    <input name="DataGrid1:_ctl2:textBox" type="text" value="someText"
    id="DataGrid1__ctl2_textBox" style="width:140px;" />
    </td></tr>
    </table>


    for the first column I can use:
    var column1 = table.rows[rowIndex].cells[0].childNodes[0].data;
    and I get 'someText'

    how can I get text from column2 ('someText2')?

    Thanks

  2. Default Re: Get data from textbox inside a table

    Simon wrote:
    > how can i get data from this table:
    > <table>
    > <tr><td>someText</td></tr>
    > <tr><td>
    > <input name="DataGrid1:_ctl2:textBox" type="text" value="someText"
    > id="DataGrid1__ctl2_textBox" style="width:140px;" />
    > </td></tr>
    > </table>
    >
    >
    > for the first column I can use:
    > var column1 = table.rows[rowIndex].cells[0].childNodes[0].data;


    I would use the generic

    var column1 = table.rows[rowIndex].cells[0].childNodes[0].nodeValue;

    with the more reliable

    var column1 = [];

    for (var c = table.rows[rowIndex].cells[0].childNodes, i = 0;
    i < c.length; i++)
    {
    column1.push(c[0].nodeValue);
    }

    column1 = column1.join("");

    or (from DOM Level 3 Core)

    var column1 = table.rows[rowIndex].cells[0].textContent;

    > and I get 'someText'
    >
    > how can I get text from column2 ('someText2')?


    Column 2 does not contain non-whitespace text nodes, therefore .textContent
    will not yield anything but whitespace.

    Suppose you wish to retrieve the value of the `input' element, you would
    retrieve the object reference with

    var o = document.forms[...].elements["DataGrid1__ctl2_textBox"];

    (preferable) or

    var o = document.getElementById("DataGrid1__ctl2_textBox");

    and then (after a runtime feature test) access

    o.value


    BTW, the first `td' element should probably be a `th' element.


    PointedEars
    --
    Anyone who slaps a 'this page is best viewed with Browser X' label on
    a Web page appears to be yearning for the bad old days, before the Web,
    when you had very little chance of reading a document written on another
    computer, another word processor, or another network. -- Tim Berners-Lee

  3. Default Re: Get data from textbox inside a table

    Thomas 'PointedEars' Lahn wrote:
    > var column1 = [];
    >
    > for (var c = table.rows[rowIndex].cells[0].childNodes, i = 0;
    > i < c.length; i++)
    > {
    > column1.push(c[0].nodeValue);


    Should read

    column1.push(c[i].nodeValue);

    of course.

    > }



    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

  4. Default Re: Get data from textbox inside a table

    On Nov 15, 11:13 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
    wrote:
    > Thomas 'PointedEars' Lahn wrote:
    > > var column1 = [];

    >
    > > for (var c = table.rows[rowIndex].cells[0].childNodes, i = 0;
    > > i < c.length; i++)
    > > {
    > > column1.push(c[0].nodeValue);

    >
    > Should read
    >
    > column1.push(c[i].nodeValue);
    >
    > of course.
    >
    > > }

    >
    > PointedEars
    > --
    > "Use any version of Microsoft Frontpage to create your site. (This won't
    > prevent people from viewing your source, but no one will want to steal it.)"
    > -- from <http://www.vortex-webdesign.com/help/hidesource.htm>


    Thanks a lot.

+ Reply to Thread

Similar Threads

  1. TextBox Within Table Wider Than Cell
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 09-28-2007, 03:36 AM
  2. Searching a TextBox value from Table dynamically
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 05-09-2007, 01:24 PM
  3. Deleting a textbox containing a table craches indesign
    By Application Development in forum Adobe Indesign
    Replies: 1
    Last Post: 01-25-2007, 08:12 AM
  4. How to copy one table inside cells of another table..?
    By Application Development in forum Adobe Indesign
    Replies: 0
    Last Post: 11-06-2006, 06:11 AM
  5. Textbox value validation using database table
    By Application Development in forum Inetserver
    Replies: 5
    Last Post: 03-20-2006, 02:41 AM