Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my element value not getting changed? Am I using the wrong function?

Tags:

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?

like image 960
devforall Avatar asked Jan 25 '09 11:01

devforall


1 Answers

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'; 
like image 172
Ferdinand Beyer Avatar answered Oct 10 '22 05:10

Ferdinand Beyer