Pass the Input text value in a TD cell using DOM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swetha123
    New Member
    • Dec 2008
    • 5

    Pass the Input text value in a TD cell using DOM

    hello , I need to alert the value entered in the text box,which is in TD cell, using DOM
    can any one tell how please
    here is the code with out a text box which is working
    Code:
    <html> 
    <head> 
    <script type="text/javascript"> 
    function cell() 
    { 
    var x=document.getElementById('myTable').rows[0].cells; 
    alert(x[0].innerHTML); 
    } 
    </script> 
    </head> 
    <body> 
    <table id="myTable" border="1"> 
    <tr> 
    <td>cell 1</td> 
    <td>cell 2</td> 
    </tr> 
    <tr> 
    <td>cell 3</td> 
    <td>cell 4</td> 
    </tr> 
    </table> 
    <br /> 
    <input type="button" onclick="cell()" value="Alert first cell"> 
    </body> 
    </html>
    here is what i need
    Code:
    <html> 
    <head> 
    <script type="text/javascript"> 
    function cell() 
    { 
    var x=document.getElementById('myTable').rows[0].cells; 
    alert(x[1].firstChild.Value); 
    } 
    </script> 
    </head> 
    <body> 
    <table id="myTable" border="1"> 
    <tr> 
    <td>cell 1</td> 
    <td><input type="text" id="txt"></td> 
    </tr> 
    <tr> 
    <td>cell 3</td> 
    <td>cell 4</td> 
    </tr> 
    </table> 
    <br /> 
    <input type="button" onclick="cell()" value="Alert first cell"> 
    </body> 
    </html>
    but i can't see the output if anything wromg please tell me
    thanks
    Swetha
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    JavaScript is case-sensitive, so it should be "value", not "Value".

    Comment

    Working...