Let's get started with a JavaScript Web Page!
- Open Notepad++
- Open your
index.html
file
- Open your
styles.css
file
- Click: New -> File
- Copy the JavaScript Page Template (HTML) code (below)
- Paste that code into your new file
- Click:
Save
- Name the file:
javascript.html
- Change the
Save as type:
to: Hyper Text Markup Language file (*.html)
- Click: New -> File
- Copy the JavaScript Code Template (JS) code (below)
- Paste that code into your new file
- Click:
Save
- Save that file in your
includes
folder
- Name the file:
javascript.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 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 Page Template (HTML)
<!doctype html>
<html>
<head>
<title>page title goes here</title>
<!-- put your name in this comment line -->
<link href="includes/styles.css" rel="stylesheet"/>
<script src="includes/javascript.js"></script>
</head>
<body>
<h1>put page heading here</h1>
<p>Required fields marked with: <span style="color: red; font-weight: bold;">*</span*> </p>
<form id="myForm" name="myForm" method="POST" onsubmit="convertTemp()">
<fieldset>
<legend>put name of form here</legend>
<span style="color: red; font-weight: bold;">*</span*> <label for="firstName">First Name:
<span style="color: red; font-weight: bold;">*</span></label>
<input type="text" id="firstName" name="firstName" size="25"
required placeholder="Enter your first name here"><br>
<span style="color: red; font-weight: bold;">*</span*> <label for="lastName">Last Name:
<span style="color: red; font-weight: bold;">*</span></label>
<input type="text" id="lastName" name="lastName" size="25"
required placeholder="Enter your last name here"><br>
<span style="color: red; font-weight: bold;">*</span*> <label for="tempF">Fahrenheit Temperature:
<span style="color: red; font-weight: bold;">*</span></label>
<input type="number" id="tempF" name="tempF" size="2" required><br>
<input type="submit" id="submit" name="submit" value="Convert">
</fieldset>
</form>
<div id="today"></div>
<script>
document.getElementById("today").innerHTML = Date();
</script>
<p>This page was last modified on:
<script>document.write(document.lastModified);</script>.</p>
</body>
</html>
JavaScript Code Template (JS)
/* put your name in this comment line */
function convertTemp () {
var fName = document.forms["myForm"]["firstName"].value;
var lName = document.forms["myForm"]["lastName"].value;
var fTemp = document.forms["myForm"]["tempF"].value;
var cTemp = (fTemp - 32) * 5 / 9;
alert("Hello " + fName + " " + lName + " " + fTemp + "F converts to " + cTemp + "C");
}
JavaScript Styles (CSS)
#today {
color: navy;
font-size: 8pt;
font-style: italic;
text-align: right;
}
Example