alert box for a calculation field

meepsittE

New Member
How can I have an alert box pop up if the number in the \[code\]Answer_2\[/code\] field is greater than 10, or less than -10? Here's my exampleJavascript: \[code\] function CalculateIMSUB(Atext, Btext, form, val) { var A = eval(Atext); var B = eval(Btext); if (isNaN(A)) A = 0; if (isNaN(B)) B = 0; var answer = A - B; form.Answer.value = http://stackoverflow.com/questions/14445728/answer; var diff = answer - val; if (diff == 0) form.Answer_2.value ='ok'; else if (diff < 0) form.Answer_2.value = http://stackoverflow.com/questions/14445728/diff; else form.Answer_2.value ='+' + diff; } function calculateAll() { var forms = document.getElementsByTagName("form"); for(var i = 0; i < forms.length; i++ ) { CalculateIMSUB(forms.input_A.value, forms.input_B.value,forms, 96) } }\[/code\]HTML:\[code\] <FORM NAME="Calculator" METHOD="GET"> <P><INPUT TYPE=TEXT NAME="input_A" SIZE=10><INPUT TYPE=TEXT NAME="input_B" SIZE=10> <INPUT TYPE="button" VALUE="http://stackoverflow.com/questions/14445728/+" name="subtractbutton" onclick="CalculateIMSUB (this.form.input_A.value, this.form.input_B.value, this.form, 96)"> <INPUT TYPE=TEXT NAME="Answer" SIZE=12><tt>96</tt><INPUT TYPE=TEXT NAME="Answer_2" SIZE=4></P></form> <input type="button" onclick="calculateAll()" value="http://stackoverflow.com/questions/14445728/Master calculation" />\[/code\]Thanks very much in advance
 
Back
Top