THis webpage calculates 2 numbers. However the validation won’t work. If user typed in space or letters in the textbox, an alert box should pop out saying that its an invalid entry. Please check my codes.. I really need your help guys..!!! Thanks
[QUOTE]
<HEAD>
<title>Radio</title>
<style type=”text/css”>
body
{
background-color:#B8BFD8;
}
</style>
<SCRIPT LANGUAGE=”JavaScript”>
function checkentry(a)
{
if(a.length>0 && Number(a)) {return true; }
else { alert(“invalid entry”); return false; }
}
function a_plus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a+b
form.ans.value = c
}
function a_minus_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a-b
form.ans.value=c
}
function a_times_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a*b
form.ans.value=c
}
function a_div_b(form) {
a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.ans.value = c
}
</SCRIPT>
<BODY>
<form>
<table>
<tr>
<td><b>Enter first number: </b></td>
<td><input type=text size=4 name=”a” value=” ” onblur=”checkentry(this.value)”></td>
</tr>
<tr>
<td><b>Enter second number: </b></td>
<td><input type=text size=4 name=”b” value=” ” name=”b”></td>
</tr>
<tr>
<td><b>Addition</b></td>
<td><input type=radio value=” + ” name=”operator” onClick=”a_plus_b(this.form)”>**</td>
</tr>
<tr>
<td><b>Subtraction</b></td>
<td><input type=radio value=” – ” name=”operator” onClick=”a_minus_b(this.form)”> </td>
</tr>
<tr>
<td><b>Multiplication</b></td>
<td><input type=radio value=” x ” name=”operator” onClick=”a_times_b(this.form)”>**</td>
</tr>
<tr>
<td><b>Division</b></td>
<td><input type=radio value=” / ” name=”operator” onClick=”a_div_b(this.form)”>* </td>
</tr>*
<tr>
<td><b>Equals</b></td>
<td><input type “number” value=0 name=”ans” size=9></td>
</tr>
<tr>
<td></td>
<td><input type=”reset” value=”Reset!”></td>
</tr>
</table>
</FORM>
</body>
</html>