Home >Web Front-end >JS Tutorial >How to Set a Default Value for an Input Field Using JavaScript?
How to Set Default Value in Input Field Using JavaScript
Setting the default value of an HTML input text field in JavaScript is straightforward. To achieve this:
Locate the Input Field:
Assign the Default Value:
Set the value property of the input field to the desired default value. For example:
document.getElementById('default-value').value = 'My Default Value';
By following these steps, you can easily set the default value of an input text field in JavaScript, allowing users to quickly fill in forms with predefined information.
The above is the detailed content of How to Set a Default Value for an Input Field Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!