I have a table which is being dynamically populated, each row contains two textfields which can be edited. When the user click the save button, i want to read al those entered values and updated accordingly:
echo "<td><input value='".$row[0]."' type='hidden'>$sql1[0]</td><td>$sql1[1]</td>
<td><input type='text' id='disc-".$row[0]."' value='".$row[3]."'></td>
The $row[0] is the ID of that row in the database and $row[3] is the value currently stored. What i am trying to achieve is that once the user clicks save, i read the value entered by the user in the textfield based on the ID so that it can be updated. For that have a javascript that selects those elements:
for(var i = 0; i < $('#order_basket [id |= "disc"]').length; i++) {
alert($('#order_basket [id|="disc"]')??.val());
}
Now the length returned is correct but i am trying to read in the id and the value which will be further stored in an array.
NOTE: there are more than 1 textfields in the same row, the other textfield has the id='disc-".$row[0]."'
Try this.
Now
valuesobject will contain id/value pair of each of the input elementsNote that I am using attribute starts with selector
^=to find all the input elementsUpdate based on OP’s comment.