I have an asp.net mvc application and i am trying to assign value to my textbox dynamically, but it seems to be not working (I am only testing on IE right now). This is what I have right now..
document.getElementsByName('Tue').Value = tue;
(by the way tue is a variable)
I have also tried this variation but it didnt work either.
document.getElementsById('Tue').Value = tue;
(by the way tue is a variable)
Can someone where please tell me where I am going wrong with this?
How to address your textbox depends on the HTML-code:
<!-- 1 --><input type="textbox" id="Tue" /> <!-- 2 --><input type="textbox" name="Tue" />
If you use the 'id' attribute:
var textbox = document.getElementById('Tue');
for 'name':
var textbox = document.getElementsByName('Tue')[0]
(Note that getElementsByName() returns all elements with the name as array, therefore we use [0] to access the first one)
Then, use the 'value' attribute:
textbox.value = 'Foobar';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With