gs99
Programmer
- Oct 7, 2001
- 40
Trying to have html file that enables user to change font styles, starting with headers.
Using Internet Explorer 7.
Html file has external CSS and Javascript files and a form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html lang="en">
<head>
<link id="styleHeaders" rel="stylesheet" type="text/css" href="styles/styleHeadersRoman.css">
<script type="text/javascript" src="scripts/style.js"></script>
<title>Set styles for web page</title>
</head>
<body>
<h3>Set styles for web page. This is how "headers" will appear</h3>
<form name="formOne" onsubmit="setStyle()">
Header font type
<select name="headers">
<option value="arial">Arial, sans-serif (default)
<option value="roman">Roman, serif
<option value="courier" >Courier, monospace
</select>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Javascript file has this:
alert("1 Start script");
function setStyle()
{
setHeadersStyle();
}
function setHeadersStyle()
{
var setHeaders="styles/styleHeaders"; // left side of href value
switch (document.formOne.headers.value)
{
case "arial":
setHeaders =setHeaders + "Arial.css"; // right side of href value
break;
case "roman":
setHeaders =setHeaders + "Roman.css"; // right side of href value
break;
case "courier":
setHeaders =setHeaders + "Courier.css"; // right side of href value
break;
}
document.getElementById('styleHeaders').href = setHeaders;
alert("2_setHeaders value: "+setHeaders);
}
What happens:
See Alert "1_Start script"
Click OK.
See HTML page with headers in default Roman font, as specified in styles/styleHeadersRoman.css.
Click Submit.
H3 header now displays in Arial font.
See Alert "2_setHeaders value: styles/styleHeadersArial.css"
Click OK.
See Alert "1_Start script"
Click OK.
See HTML page with headers in default Roman font again.
Question- Why doesn't the Arial font stay?
Using Internet Explorer 7.
Html file has external CSS and Javascript files and a form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html lang="en">
<head>
<link id="styleHeaders" rel="stylesheet" type="text/css" href="styles/styleHeadersRoman.css">
<script type="text/javascript" src="scripts/style.js"></script>
<title>Set styles for web page</title>
</head>
<body>
<h3>Set styles for web page. This is how "headers" will appear</h3>
<form name="formOne" onsubmit="setStyle()">
Header font type
<select name="headers">
<option value="arial">Arial, sans-serif (default)
<option value="roman">Roman, serif
<option value="courier" >Courier, monospace
</select>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Javascript file has this:
alert("1 Start script");
function setStyle()
{
setHeadersStyle();
}
function setHeadersStyle()
{
var setHeaders="styles/styleHeaders"; // left side of href value
switch (document.formOne.headers.value)
{
case "arial":
setHeaders =setHeaders + "Arial.css"; // right side of href value
break;
case "roman":
setHeaders =setHeaders + "Roman.css"; // right side of href value
break;
case "courier":
setHeaders =setHeaders + "Courier.css"; // right side of href value
break;
}
document.getElementById('styleHeaders').href = setHeaders;
alert("2_setHeaders value: "+setHeaders);
}
What happens:
See Alert "1_Start script"
Click OK.
See HTML page with headers in default Roman font, as specified in styles/styleHeadersRoman.css.
Click Submit.
H3 header now displays in Arial font.
See Alert "2_setHeaders value: styles/styleHeadersArial.css"
Click OK.
See Alert "1_Start script"
Click OK.
See HTML page with headers in default Roman font again.
Question- Why doesn't the Arial font stay?