I´m trying to create a function to change input value in the HTML script. HTML looks like this:
<tr>
<td>6500</td>
<td>
<input type="text" size="3" value="3"/>
</td>
</tr>
<tr>
<td>6500</td>
<td>
<input type="text" size="3" value="3"/>
</td>
</tr>
I want to create an event where the value updates depending on the userinput and change the value so that when I click the button it performs the calculation which Ive already written functions for. I am getting stuck, only thing I have is the cells where userinput is an option. I need to do simle plain js and not jquery.
function input() {
var table = document.getElementById("list");
var x = table.getElementsByTagName("input");
console.log(x);
}
Thanks in advance.
Not sure why I never replied with an answer after your follow up comment, and I know this is terribly late, but if this no longer helps you, it may still help others.
Using JavaScript:
var inputs = document.querySelectorAll('input');
for (var i = 0; i < inputs.length; i++) {
inputs[i].addEventListener('input', function() {
this.setAttribute('value', this.value);
});
}
Using jQuery:
$(document).on('input', 'input', function() {this.setAttribute('value', this.value);});
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.