Thursday, October 27, 2022

[FIXED] How to get input value with no id using JavaScript?

Issue

I have an editable DataTabe and when edit mode, the generated html is exactly as shown below:

<td><form><input autocomplete="off" name="value" ></form></td>

There is s TextBox as input and I need t get the value of this input. However, I cannot give id as there is no configuration of DataTable and I decided to get the value using Javaascipt. I have tried many different methods like closest() as shown below, but cannot get the value. Is it possible to grab it?

var $row = $(this).closest("tr"); 
$tds = $row.find("td");

Solution

You might use document.querySelector:

var input = document.querySelector('[name="value"]`);

Or, using jQuery, you could also use the same selector:

var input = $('[name="value"]');


Answered By - Matías Fidemraizer
Answer Checked By - David Goodson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.