tags:

views:

2639

answers:

4

hi everyone,

I have an asp.net mvc application and i am trying to assign value to my textboxe 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 somone where plz tell me where am i going wrong with this

+1  A: 

Sounds like we need to assume that your textbox name and ID are both set to "Tue." If that's the case, try using a lower-case V on .value.

Jeff Handley
+1  A: 

It's document.getElementById, not document.getElementsByID

I'm assuming you have <input id="Tue" ...> somewhere in your markup.

Paul Dixon
sorry that was a typo just fixed it.
devforall
u were right about the getElements its getElementByID and i had getElementsById .. good catch thanx
devforall
+1  A: 

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';
Ferdinand Beyer
A: 

As the plural in getElementsByName() implies, does it always return list of elements that have this name. So when you have an input element with that name:

<input type="text" name="Tue">

And it is the first one with that name, you have to use document.getElementsByName('Tue')[0] to get the first element of the list of elements with this name.

Beside that are properties case sensitive and the correct spelling of the value property is .value.

Gumbo