Hi and thanks to anyone who can help, I'm brand new to html and keen to learn, but stuck on what I think is a very simple problem, can anyone point me in the right direction.
I want to return a value to a input field [Answer] based upon what is entered into another input field [width]
I think I have the If expression right, I just can't seem to make the result appear in the Answer field.
Here's the script I have: Thanks again
<SCRIPT LANGUAGE="JavaScript">
function Calculate(form){
var Answer
if(width >= 1 && width <= 110){
Answer = "1"
}
if(width >= 111 && width <= 160){
Answer = "1.5"
}
if (width >=161 && width <= 200){
Answer = "2"
}
if (width >=201 && width <= 240){
Answer = "2.5"
}
if (width >=241 && width <= 280){
Answer = "3"
}
// end of JavaScript functions -->
</SCRIPT>
</HEAD>
<BODY>
<P><FONT SIZE="+2">Simple Adder</FONT></P>
<FORM NAME="Calculator" METHOD="post">
<P>Enter a number: <INPUT NAME="width" TYPE=TEXT id="width" SIZE=10>
</P>
<P>
<INPUT TYPE="button" VALUE="Calculate" name="ClearButton" onClick="Calculate(this.form)">
</P>
<P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P>
</FORM>
</BODY>
</HTML>
I want to return a value to a input field [Answer] based upon what is entered into another input field [width]
I think I have the If expression right, I just can't seem to make the result appear in the Answer field.
Here's the script I have: Thanks again
<SCRIPT LANGUAGE="JavaScript">
function Calculate(form){
var Answer
if(width >= 1 && width <= 110){
Answer = "1"
}
if(width >= 111 && width <= 160){
Answer = "1.5"
}
if (width >=161 && width <= 200){
Answer = "2"
}
if (width >=201 && width <= 240){
Answer = "2.5"
}
if (width >=241 && width <= 280){
Answer = "3"
}
// end of JavaScript functions -->
</SCRIPT>
</HEAD>
<BODY>
<P><FONT SIZE="+2">Simple Adder</FONT></P>
<FORM NAME="Calculator" METHOD="post">
<P>Enter a number: <INPUT NAME="width" TYPE=TEXT id="width" SIZE=10>
</P>
<P>
<INPUT TYPE="button" VALUE="Calculate" name="ClearButton" onClick="Calculate(this.form)">
</P>
<P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P>
</FORM>
</BODY>
</HTML>