-
Notifications
You must be signed in to change notification settings - Fork 3
/
09 variables 2.html
21 lines (19 loc) · 939 Bytes
/
09 variables 2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html lang="en">
<head><title>Variables example</title>
</head>
<body>
<input id="textinput" type="text"> <!-- the default type of input is text-->
<button id="button">update text below</button>
<p id="textToChange" >This is some text</p>
<!-- change text of p tag by whatever is written in input -->
<script type="text/javascript">
document.getElementById("button").onclick=function(){
var textEntered=""; // tells the browser that its string variable but initially its empty
textEntered=document.getElementById("textinput").value;
//this will set the value that user has typed into the textentered variable
document.getElementById("textToChange").innerHTML=textEntered;
// p tag will be updated with new text in textEntered variable
}
</script>
</body>
</html>