I want to get the value of the input field using js or jquery of the following tr of a table-
<tr>
<td class="center"> <div class="hide"> <?php echo $row['id']; ?> </div> </td>
<td class="center"> <div class="hide"> <?php echo $row['employee_no']; ?> </div>
<input type="tel" name="employee_no" id="employee_no" value="<?php echo
$row['employee_no']; ?>" onchange="return validate()" > </td>
</tr>
I try this code-
function update(thisrow){
var Row = document.getElementById(thisrow);
var Cells = crw.getElementsByTagName("td");
var id = Cells[0].innerText;
var employee = Cells[1].innerText;}
Unfortunately, it gives the correct value of id but gives blank value of the employee? How can I get the value of employee from td input using JS or Jquery?
just grab the element and get the value.
function validate() { let t = document.getElementsByTagName("table")[0] let trs = t.getElementsByTagName("tr") for (i = 0; i < trs.length; i++) { let tds = trs[i].getElementsByTagName("td") for (j = 0; j < tds.length; j++) { let inp = tds[j].getElementsByTagName("input") if (inp.length > 0) console.log(inp[0].value) } } }
<table> <tr> <td class="center"> <div class="hide"> <?php echo $row['id']; ?> </div> </td> <td class="center"> <div class="hide"> <?php echo $row['employee_no']; ?> </div> <input type="tel" name="employee_no" id="employee_no" value="000-123-1234" onchange="validate()"> </td> </tr> </table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.