Let's get started with a JavaScript Prompt Web Page!
Open Notepad++
Open your index.html file
Open your styles.css file
Click: New -> File
Copy the JavaScript Prompt Page Template (HTML) code (below)
Paste that code into your new file
Click: Save
Name the file: js_prompt.html
Change the Save as type:
to: Hyper Text Markup Language file (*.html)
Click: New -> File
Copy the JavaScript Prompt Code Template (JS) code (below)
Paste that code into your new file
Click: Save
Save that file in your includes folder
Name the file: prompt.js
Change the Save as type:
to: JavaScript file (*.js)
Change your page title, your Author name, and your page heading to something appropriate
Open your styles.css file
Copy the JavaScript Prompt Styles (CSS) code (below)
Paste that code into your styles.css file
Change some styles
In your index.html file
Add a link to this page. Change: <li>Create a Javascript Page</li>
to: <li><a href="javascript.html">Create a Javascript Page</a></li>
Save your changes
Click: Run
Choose: Launch in IE
or Launch in Chrome
or Launch in Firefox
View your web page
Make any changes
Save your changes
JavaScript Prompt Page Template (HTML)
<!doctype html>
<html>
<head>
<title>page title goes here</title>
<!-- Author: put your name in this comment line -->
<link href="includes/styles.css"rel="stylesheet"/>
<script src="includes/prompt.js"></script>
</head>
<body onload="promptMe();">
<h1>put page heading here</h1>
<div id="promptDiv">
</div>
<div id="confirmDiv">
</div>
<p>This page was last modified on:
<script>document.write(document.lastModified);</script>.</p>
</body>
</html>
JavaScript Prompt Code (JS)
/* put your name in this comment line */function promptMe () {
var person = prompt("Please enter your name", "Bob Dylan");if (person != null) {
document.getElementById("promptDiv").innerHTML =
"Hello " + person + "! How are you today?";
}
if (confirm("OK to continue?")) {
document.getElementById("confirmDiv").innerHTML =
"You clicked 'OK'";
} else {
document.getElementById("confirmDiv").innerHTML =
"You clicked '<span style=\"color: red; font-weight: bold;\">Cancel</span>'";
}
}