<form action="" method="POST"> <table cellpadding="5" cellspacing="5" style="text-align:center;" width="100%" border="0"> <tr> </tr> <tr> </tr> </table> <table cellpadding="5" cellspacing="5" style="text-align:center;" width="100%" border="0"> <tr> </tr> <tr> </tr> </table> <br /> <br /> <input type="submit" value="Solve" onclick="return solve();" /> <input type="submit" value="Clear" onclick="return clear();" /> <br /> <br /> </form>
<script> function solve() { var operators_If = document.getElementsByName("math_Operators"); var first_TextBox_Value = document.getElementById("number1_TextBox").value; var no_two = document.getElementById("number2_TextBox").value; if (first_TextBox_Value=="") { var math_Results = "<span class='warning'>Enter the first value.</span>"; document.getElementById('math_Results').innerHTML = math_Results; return false; } else if (no_two=="") { var math_Results = "<span class='warning'>Enter the second value.</span>"; document.getElementById('math_Results').innerHTML = math_Results; return false; } if (operators_If[0].checked == true) { sum = parseInt(first_TextBox_Value) + parseInt(no_two); results = "<span class='message'> The sum of " + first_TextBox_Value + " and " + no_two + " is <b style='color:blue;'>" + sum +"</b>.</span>"; document.getElementById('math_Results').innerHTML = results; return false; } else if (operators_If[1].checked == true) { diff = parseInt(first_TextBox_Value) - parseInt(no_two); results = "<span class='message'> The difference between " + first_TextBox_Value + " and " + no_two + " is <b style='color:blue;'>" + diff +"</b>.</span>"; document.getElementById('math_Results').innerHTML = results; return false; } else if (operators_If[2].checked == true) { product = parseInt(first_TextBox_Value) *parseInt(no_two); results = "<span class='message'>The product between " + first_TextBox_Value + " and " + no_two + " is <b style='color:blue;'>" + product +"</b>.</span>"; document.getElementById('math_Results').innerHTML = results; return false; } else if (operators_If[3].checked == true) { quotient = parseInt(first_TextBox_Value) / parseInt(no_two); results = "<span class='message'>The quotient between " + first_TextBox_Value + " and " + no_two + " is <b style='color:blue;'>" + quotient +"</b>. </span>"; document.getElementById('math_Results').innerHTML = results; return false; } else { var math_Results = "<span class='warning'>Select your math operators.</span>"; document.getElementById('math_Results').innerHTML = math_Results; return false; } return true; } function reset_Operators() { document.getElementById('math_Results').innerHTML = ''; } function clear() { document.getElementById('math_Results').innerHTML = ""; first_TextBox_Value=""; no_two=""; first_TextBox_Value.focus(); } </script>
<style type="text/css"> body{ width:500px; margin:auto; border:blue 1px solid; text-align:center; } h1 { color:blue; } h2 { color:red; } label { font-size: 20px; font-weight: bolder; font-family: cursive; color: blue; } input[type="number"] { font-size: 18px; border: blue 1px solid; text-indent: 5px; width: 150px; } input[type="submit"] { font-size: 18px; color: blue; background: azure; border: blue 1px solid; padding: 6px; border-radius: 4px; cursor:pointer; } #math_Results{ font-size: 23px; font-weight: bold; font-family: cursive; color: red; } </style>