In Feburary 2016 28,
Open a text editor and create a new file named 'changeTextVars.html.' Type six HTML tags in the file:
Save 'changeTextVars.html.'
Place a JavaScript open script tag -- '' tag:
Add a JavaScript function between the '' tags named 'changeText().' The 'changeText()' function takes a variable named 'monsterName' as an argument:
Edit the 'changeText' function. Use the 'document.getElementById' function to change the 'innerHTML' property for the field named 'textToChange.' The 'textToChange' field holds the text updated with the variable 'monsterName':
Add a '' tag between the HTML '
' and '
' tags. Enter some text that displays the message -- such as 'My favorite monster is: ' -- and close the '' tag. Be sure to include a space after the colon and before the '' tag to separate the message from the dynamic text:
My favorite monster is:
Enter an open '' tag between the '' and '' tags after the 'My favorite monstor is: ' message. Assign an 'id' to the '' tag and set its value to 'textToChange.' For example, type the text 'Dracula' after the '' tag and close the '' tag:
My favorite monster is:
Dracula
Add an HTML '
' tag after the '' tag. Set the input type to 'button' and add an 'onclick()' event that calls the 'changeText' function and passes the value 'Frankenstein.' Set the input field 'value' attribute to 'Change Text.' Save and close 'changeTextVars.html.'
My favorite monster is:
Dracula
Open 'changeTextVars.html' in a Web browser. Click the 'Change Text' button to use the 'monsterName' variable to change the 'textToChange' field from 'Dracula' to 'Frankenstein.'
In Feburary 2016 28,