- (8.8)
<input type="button" value="Click to go to Yahoo"
onclick="location.href='http://www.yahoo.com/'"
/>
- (8.9) According to the book, document.title
is a read-only property, though Firefox 1.0 writes to
it fine.
- (9.9)
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function displayFullName(first, middle, last) {
alert("Your full name is " + first + " " + middle + " " + last);
}
</script>
</head>
<body>
<script>
firstName = prompt("Enter your first name", "");
middleName = prompt("Enter your middle name", "");
lastName = prompt("Enter your last name", "");
displayFullName(firstName, middleName, lastName);
</script>
</body>
</html>
- (9.10)
<script>
var vacationimage = new Image(200, 150);
vacationimage.src = "AtTheBeach.jpg";
</script>
<p><img id="myphotos" name="myphotos" src='SomeBoringImage.jpg'/></p>
<p><a href="summerphotos.htm"
onmouseover="document.myphotos.src=vacationimage.src">Click
here to see my summer photos"</a></p>
- (10.7)
function process(theMessage, theMessageBox) {
theMessageBox.value = theMessage;
}
function process(theForm) {
theForm.outputBox.value = theForm.inputBox.value;
}
- (Lab 11.4)
<html>
<head>
<title>Sales Tax Calculator</title>
<script type="text/javascript">
function roundToTwoPlaces(n) {
return Math.round(n * 100) / 100;
}
function calculateTax() {
var f = document.getElementById("taxForm");
var saleAmount = parseFloat(f.saleAmountBox.value);
var taxRate = parseFloat(f.rateBox.value) / 100;
var taxAmount = saleAmount * taxRate;
var totalAmount = saleAmount + taxAmount;
f.taxBox.value = roundToTwoPlaces(taxAmount);
f.totalAmountBox.value = roundToTwoPlaces(totalAmount);
}
</script>
</head>
<body>
<form id="taxForm">
<p>Enter the sale amount
<input type="text" id="saleAmountBox" name="saleAmountBox"
value=""
/></p>
<p>Enter the tax rate in percent
<input type="text" id="rateBox" name="rateBox"
value=""
/></p>
<p>Sales tax due
<input type="text" id="taxBox" name="taxBox"
value="" readonly="readonly"
/></p>
<p>Total amount due
<input type="text" id="totalAmountBox" name="totalAmountBox"
value="" readonly="readonly"
/></p>
<input type="button" value="Calculate" onclick="calculateTax()" />
</form>
</body>
</html>
- (67) There's no property of style objects called
background-color
-- what's needed is backgroundColor.