EN
JavaScript - set value of input field
12 points
In this article, we would like to show you how to set input field value using JavaScript.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
input {
7
padding: 10px;
8
width: 300px;
9
}
10
11
</style>
12
</head>
13
<body>
14
<input id="my-input" type="text" value="" />
15
<script>
16
17
var input = document.getElementById('my-input');
18
19
input.value = 'This text has been set from javascript code...';
20
21
</script>
22
</body>
23
</html>
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
input {
7
padding: 10px;
8
width: 300px;
9
}
10
11
</style>
12
</head>
13
<body>
14
<input id="my-input" type="text" value="" />
15
<script>
16
17
var input = document.getElementById('my-input');
18
19
input.setAttribute('value', 'This text has been set from javascript code...');
20
21
</script>
22
</body>
23
</html>
To see examples check this site.