Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i set value of a textbox using javascript

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.

like image 957
Prady Avatar asked Dec 27 '10 21:12

Prady


People also ask

How do you assign a value to a text box?

Answer: Use the jQuery val() Method You can simply use the jQuery val() method to set the value of an input text box.

How do you code a text box in JavaScript?

You can create a textbox using JavaScript in two simple steps: First, you need to use the createElement("input") method of the document object to create an <input> element. Then, you need to set the type attribute of the <input> element that you've created to "text" using the Element. setAttribute() method.

Which attribute is used to assign value to the textbox?

The “setAttribute()” method is used to assign a value to the textbox. It is utilized to add or set an attribute to a certain element and give it a value.


1 Answers

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.

like image 139
lonesomeday Avatar answered Oct 20 '22 08:10

lonesomeday