1

i have this table and it has a button on its right most column and i wanted that when i click that button, p tags will change according to the values on the row where the button is as of now here is how my table looks like

enter image description here

and my code

<table class="table table-striped table-hover" id="detailTable">
    <thead>
        <tr>
            <th>Record ID</th>
            <th>School Year</th>
            <th>School Quarter</th>
            <th>Student Name</th>
            <th></th>
        </tr>
    </thead>

    <tbody>
            <tr>
                <td>123</td>
                <td>SY 2013-2014</td>
                <td>2nd Quarter</td>
                <td>Billy Joel</td>
                <td><button class="btn" onclick="tgPanel();">Edit</button></td>

            </tr>  
            //more rows here     
    </tbody>

and here is my javascript code

function tgPanel()
{
   document.getElementById("rid").innerHTML =     document.getElementById("detailTable").rows[0].cells[1].getVal;
   document.getElementById("sy").innerHTML =  document.getElementById("detailTable").rows[0].cells[2].getVal;
   ..and so on..
}
BourneShady
  • 955
  • 2
  • 17
  • 36

1 Answers1

0

You can't get any value from your cells using "getVal" use "innerHTML" as well:

document.getElementById("rid").innerHTML = document.getElementById("detailTable").rows[0].cells[1].innerHTML;

n3sutran
  • 26
  • 4
  • hi. i change it just as you have said but the value im getting it the header name. is there a way in which the number inside row[0] will change when i click the button on a certain row? – BourneShady Oct 16 '15 at 13:52
  • 1
    It would be better to use the *textContent* (or *innerText* for older IE) property than innerHTML. – RobG Oct 16 '15 at 14:01
  • use row[0].cells[0].innerHTML = "whatever you want" – n3sutran Oct 16 '15 at 14:07