I have an <input type="text" value="0.00" id="prdtotal"/>
inside a <td>
in a table.
I want to use Javascript to compute a value and assign it to the textbox. How can I do it?
I tried using document.getElementById("prdtotal").value="1.00";
but it doesnt work. Thanks for any help!
You've found the element using getElementById
but you've not specified its the value
property you want to set.
document.getElementById("prdtotal").value="1.00"
And a live example: http://jsfiddle.net/hevwt/
Use the value attribute:
document.getElementById("prdtotal").value = "1.00";
document.getElementById() returns the actual DOM object (a handle/reference to the <input>
element).
Also note your missing double quote before the closing parenthesis.
I would suggest you to take a look at the Mozilla Developer Network (MDN):
HTMLElement : a reference of all attributes a (general) HTML element can have.
HTMLInputElement : a reference of all special attributes an input element (eg <textarea>
, <input>
) can have.
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.