Hi all
I am new to javascript, this term being my first encounter with it. However, I am familiar with asp and fairly proficient in Java. I am currently working on my first lab in Corporate Web Programming and it is a fairly simple page to just get students acquainted with CSS.
Ok the javascript portion of the lab is just to create these three text boxes, two of which contain random numbers and the third being where the user would enter the sum of these numbers. Clicking the new button generates new random numbers in the first two boxes and clicking the check button checks to see if the provided answer is correct and generates the appropriate response on the page. The problem? Well my numbers go to the textboxes just fine and I can generate new ones all day long but when I enter a number in the third box, be it the wrong or right answer, and press click I get the following error:
Line 42: document.fl.sum is null or is not an object
I will post the entirety of my code below including the html portion. Maybe I am missing something simple here
Any help/advice anyone could offer would be greatly appreciated. I am using IE ver 5.5 if that is any help. I am not looking for anyone to do my work here just feeling a little frustrated
Oh and I am aware that the whole inner text thing is not the way to get the image to display but I would like to get the first part working before I tackle that 
<html><head><title>Anna's Assignment #1</title>
<style>
Div.h1{font-family:"verdana"; font-weight:"bold"; font-size: 20pt; color: "blue";
border-style: "ridge"; border-color: "blue"; text-align: Center; background-color: "black"}
Div.b1{font-family:"verdana"; font-size: 14pt; color: "black"; text-align:"Left";
background-color: "white"}
#img{position: absolute; left: 400; top:140;}
#msg{position: absolute; left: 440; top:140; font-family:"verdana"; font-size: 16pt;
color: "black"}
#t1 {position: absolute; left: 20; top:95}
#t2 {position: absolute; left: 20; top:140}
#t3 {position: absolute; left: 20; top:185}
#b1 {position: absolute; left: 20; top:235}
#b2 {position: absolute; left: 70; top:235}
#tb1{position: absolute; left: 150; top:95}
#tb2{position: absolute; left: 150; top:140}
#tb3{position: absolute; left: 150; top:185}
</style>
<script language="javascript">
var sum, num1, num2, ans;
function getNum() //Generates random numbers
{
num1 = Math.round(100 * (Math.random()));
num2 = Math.round(100 * (Math.random()));
sum = num1 + num2;
document.f1.n1.value = num1;
document.f1.n2.value = num2;
}//end getNum
function check() //Checks answer
{
//ans = document.fl.sum.value;
if(sum = (document.fl.sum.value))
{
img.innerText = "<img border='0' src='../green.jpg' width='29' height='31'>";
msg.innerText = "Your answer is correct!";
}
else
{
img.innerText = "<img border='0' src='../red.jpg' width='29' height='31'>";
msg.innerText = "Your answer is incorrect";
}
}//end check
</script>
</head><body>
<div class = "h1">Anna Petersen's Math Help Page</div><p>
<div class = "b1"><form name = "f1" id = "f1">
<SPAN id="t1">1st Number:</SPAN><Div id="tb1"><input readonly type="text" name="n1" size="10"></Div><br>
<SPAN id="t2">2nd Number:</SPAN><Div id="tb2"><input readonly type="text" name="n2" size="10"></Div><br>
<SPAN id="t3">Sum: </SPAN><Div id="tb3"><input type="text" name="sum" size="10"></Div><br>
<SPAN id="b1"><input type="button" name="New" value="New" onClick="getNum()"></span>
<SPAN id="b2"><input type="button" name="Check" value="Check" onClick="check()"></span>
</form></div>
<SPAN id = "img"></SPAN>
<SPAN id = "msg"></SPAN>
</body></html>
Thank you in advance!
This lab is due bright and early Monday morning... hehe.
Oh and a note the commented out line
//ans = document.fl.sum.value;
Was just me trying different approaches to getting the value out of the text box.
Ok the javascript portion of the lab is just to create these three text boxes, two of which contain random numbers and the third being where the user would enter the sum of these numbers. Clicking the new button generates new random numbers in the first two boxes and clicking the check button checks to see if the provided answer is correct and generates the appropriate response on the page. The problem? Well my numbers go to the textboxes just fine and I can generate new ones all day long but when I enter a number in the third box, be it the wrong or right answer, and press click I get the following error:
Line 42: document.fl.sum is null or is not an object
I will post the entirety of my code below including the html portion. Maybe I am missing something simple here
<html><head><title>Anna's Assignment #1</title>
<style>
Div.h1{font-family:"verdana"; font-weight:"bold"; font-size: 20pt; color: "blue";
border-style: "ridge"; border-color: "blue"; text-align: Center; background-color: "black"}
Div.b1{font-family:"verdana"; font-size: 14pt; color: "black"; text-align:"Left";
background-color: "white"}
#img{position: absolute; left: 400; top:140;}
#msg{position: absolute; left: 440; top:140; font-family:"verdana"; font-size: 16pt;
color: "black"}
#t1 {position: absolute; left: 20; top:95}
#t2 {position: absolute; left: 20; top:140}
#t3 {position: absolute; left: 20; top:185}
#b1 {position: absolute; left: 20; top:235}
#b2 {position: absolute; left: 70; top:235}
#tb1{position: absolute; left: 150; top:95}
#tb2{position: absolute; left: 150; top:140}
#tb3{position: absolute; left: 150; top:185}
</style>
<script language="javascript">
var sum, num1, num2, ans;
function getNum() //Generates random numbers
{
num1 = Math.round(100 * (Math.random()));
num2 = Math.round(100 * (Math.random()));
sum = num1 + num2;
document.f1.n1.value = num1;
document.f1.n2.value = num2;
}//end getNum
function check() //Checks answer
{
//ans = document.fl.sum.value;
if(sum = (document.fl.sum.value))
{
img.innerText = "<img border='0' src='../green.jpg' width='29' height='31'>";
msg.innerText = "Your answer is correct!";
}
else
{
img.innerText = "<img border='0' src='../red.jpg' width='29' height='31'>";
msg.innerText = "Your answer is incorrect";
}
}//end check
</script>
</head><body>
<div class = "h1">Anna Petersen's Math Help Page</div><p>
<div class = "b1"><form name = "f1" id = "f1">
<SPAN id="t1">1st Number:</SPAN><Div id="tb1"><input readonly type="text" name="n1" size="10"></Div><br>
<SPAN id="t2">2nd Number:</SPAN><Div id="tb2"><input readonly type="text" name="n2" size="10"></Div><br>
<SPAN id="t3">Sum: </SPAN><Div id="tb3"><input type="text" name="sum" size="10"></Div><br>
<SPAN id="b1"><input type="button" name="New" value="New" onClick="getNum()"></span>
<SPAN id="b2"><input type="button" name="Check" value="Check" onClick="check()"></span>
</form></div>
<SPAN id = "img"></SPAN>
<SPAN id = "msg"></SPAN>
</body></html>
Thank you in advance!
Oh and a note the commented out line
//ans = document.fl.sum.value;
Was just me trying different approaches to getting the value out of the text box.