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.
Answer: Use the jQuery val() Method You can simply use the jQuery val() method to set the value of an input text box.
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.
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.
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.
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