how do i set value of a textbox using javascript
Asked Answered
A

1

8

I am trying to get a value fro query string and assign that value into a textbox. I am able to get the value from query string but unable to assign it to textbox.

document.getElementByName('Contact0Email').Value = email;

Tried the above code but doesn't seem to be working. Though the alert of email gives the right value.

Amboise answered 27/12, 2010 at 21:8 Comment(4)
If you're just beginning with javascript, I suggest you take a look at the f-a-n-t-a-s-t-i-c jQuery library - jquery.com. In jquery you'd do the following: $("#Contact0Email").val(email);Jibe
Also, I think you'd have better luck with getElementById instead of getElementsByName (note the 's' in Elements)Spoilfive
@yuval: I'd argue that it's better to get an appreciation of the DOM API first. Then use one of the many libraries available if you want. Knowing the DOM API helps prevent library abuse.Seafaring
@yuval, you're not going to load a 26 KB library just to save 26 characters.Emelia
C
25

You need a lower-case value and a plural Elements:

document.getElementsByName('Contact0Email')[0].value = email;

You need the [0] to get the first element in the list. Names don't have to be unique like ids.

Coulometer answered 27/12, 2010 at 21:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.