Well, the title speaks for itself. What I am trying to do is the following:
Code:
Create Form with the following elements:
One Text box, Temp, to accept a temperature value. Two command buttons
-One to invoke a function described in the next step
-One to RESET form elements
Than:
Does your Last Name begin with A- L ?
-If answered yes: is temp >80?
-if answered yes: display “it is okay out there” in back letters
Than (end)
-if answered no: display: “ it is sweltering out there” in red letters
Than (end)
-If answered no: is temp <60?
-if answered yes: display: “its is freezing out there” in blue letters
Than (end)
-If answered no: display: “ it is okay out there” in black letters
Than (end)
And here is the code I have thus far:
Code:
<html>
<head>
<script type="text/javascript">
var temp = 90;
var first = true;
if(first == true){
if(temp >= 80){
document.write("It is okay out there.");
}else if(temp <= 60){
document.write("It is freezing out there.");
} else {
document.write("It is okay out there.");
}}
else if(temp >= 80){
document.write("It is okay out there.");
}else if(temp <= 60){
document.write("It is freezing out there.");
} else {
document.write("It is okay out there.");
}
</script>
</head>
<body>
<FORM NAME="nametemp">
<H1>Last Name & Weather Questionaire</H1>
<p><strong>Does your Last Name begin with A- L?</strong></p>
<INPUT TYPE="BUTTON" VALUE="Yes" onClick="first.value='true'"><INPUT TYPE="BUTTON" VALUE="No" onClick="first.value='false' ">
<p>
<INPUT TYPE="TEXT" NAME="tempf" VALUE="0" SIZE=4 MAXLENGTH=6>
<font size="+1">Temperature</font>
<INPUT TYPE="BUTTON" VALUE="Set Temp Variable" onClick="temp.value='' "></br></br>
</p>
<input type="reset" value="Reset!">
<br>
</FORM></body>
</html>
Obviously, it does not work. I have never written JS before and am trying to help out my sister who is taking a CS course. Either way, what I think I am doing wrong has to do with the form submissions. The ONCLICK parameters don't seem to be setting the VAR's to the proper values, or even at all. I've seen some scripts where the ONCLICK is in the JS itself and the HTML just contains references to the ID's established in the script, but shouldn't this work too? Hope you can help and thanks in advance!
Regards.