Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the value of an input field

How would you set the default value of a form <input> text field in JavaScript?

like image 508
SebastianOpperman Avatar asked Sep 30 '11 10:09

SebastianOpperman


People also ask

How do you get the input field value in react?

To get the value of an input field in React:Use event. target. value to get the input field's value and update the state variable.

How do I set the value of a element in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.


1 Answers

This is one way of doing it:

document.getElementById("mytext").value = "My value"; 
like image 65
James Avatar answered Oct 13 '22 00:10

James