HTML/JavaScript Help Please!?

  • Thread starter Thread starter Sir_Peech
  • Start date Start date
S

Sir_Peech

Guest
I want to be able to take in information from multipul text boxes and input the information into a function which will then do math with them. if anyone can give me some example code that has an alert show the info, that would be awesome!!!! or you could email me the example code at my email address...
 
Simple Example:-

<html>
<script type="text/javascript">

function add(){
var x = parseInt( document.getElementById( "input1" ).value );
var y = parseInt( document.getElementById( "input2" ).value );

if(!isNaN(x)&&!isNaN(y))
alert(x+y);
}

function sub(){
var x = parseInt( document.getElementById( "input1" ).value );
var y = parseInt( document.getElementById( "input2" ).value );

if(!isNaN(x)&&!isNaN(y))
alert(x-y);
}

function mul(){
var x = parseInt( document.getElementById( "input1" ).value );
var y = parseInt( document.getElementById( "input2" ).value );

if(!isNaN(x)&&!isNaN(y))
alert(x*y);
}

function div(){
var x = parseInt( document.getElementById( "input1" ).value );
var y = parseInt( document.getElementById( "input2" ).value );

if(!isNaN(x)&&!isNaN(y)&&y!=0)
alert(x/y);
}
</script>

<body>
<input id="input1" type="text" />
<input id="input2" type="text" />
<br />
<input id="add" type="button" value=" + " onClick="add()" />
<input id="sub" type="button" value=" - " onClick="sub()" />
<input id="mul" type="button" value=" * " onClick="mul()" />
<input id="div" type="button" value=" / " onClick="div()" />
</body>
</html>
 
Back
Top