- Code: Select all
<html>
<head>
<script language="javascript">
function fadd()
{
var first,sec,res;
//Take the value of first textbox and convert it to float
first=parseFloat(document.forms[0].txt1st.value);
//Take the value of second textbox and convert it to float
sec=parseFloat(document.forms[0].txt2nd.value);
res=first+sec;
//show the result in alertbox
alert("the result"+res);
//show the result in the result textbox
document.forms[0].txtresult.value=res;
}
function fminus()
{
var first,sec,res;
first=parseFloat(document.forms[0].txt1st.value);
sec=parseFloat(document.forms[0].txt2nd.value);
res=first-sec;
alert("the result"+res);
document.forms[0].txtresult.value=res;
}
function fdiv()
{
var first,sec,res;
first=parseFloat(document.forms[0].txt1st.value);
sec=parseFloat(document.forms[0].txt2nd.value);
res=first/sec;
alert("the result"+res);
document.forms[0].txtresult.value=res;
}
function fmult()
{
var first,sec,res;
first=parseFloat(document.forms[0].txt1st.value);
sec=parseFloat(document.forms[0].txt2nd.value);
res=first*sec;
alert("the result"+res);
document.forms[0].txtresult.value=res;
}
</script>
</head>
<body>
<p> Enter two values in 1st number and 2nd number box. Then check what you want to do with value.</p>
<p>After checking add, subtract, multiply or divide, a result will display</p>
<form name="cal" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="19%"><div align="left">Enter 1st number
</div></td>
<td width="81%"><input name="txt1st" type="text" id="txt1st"></td>
</tr>
<tr>
<td><div align="left">Enter 2nd number
</div></td>
<td><input name="txt2nd" type="text" id="txt2nd"></td>
</tr>
<tr>
<td height="28"><div align="left">Result
</div></td>
<td height="28"><input name="txtresult" type="text" id="txtresult"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table> <td> add: <input name="btnadd" type="radio" id="btnadd" value="+" onclick="fadd()"></td><br/>
<td>subtrack <input name="btnminus" type="radio" id="btnminus" value="-" onClick="fminus()"></td><br/>
<td> divide<input name="btndiv" type="radio" id="btndiv" value="%" onClick="fdiv()"></td><br/>
<td> multiply<input name="btnmult" type="radio" id="btnmult" value="*" onClick="fmult()"></td><br/>
</form>
</body>
</html>
here is my code, it calculated good but why when i click add and gives result it doesnt uncheck it still there, if u guys try it u can see what im talking about

