forms - Javascript Two calculators on one site -
hi have code on site`
<body> <script> function calcresult() { document.getelementbyid('result').innerhtml = ''; var num1 = new number(document.getelementbyid('txt1').value); var num2 = new number(document.getelementbyid('txt2').value); if (isnan(num1) || isnan(num2)) { alert('one or both inputs not number'); } else { document.getelementbyid('result').innerhtml = num1 * num2; } } window.onload = function() { document.getelementbyid('btncalc').onclick = calcresult; } </script> <div> enter value 1 <input type="text" id="txt1" /> <br />enter value 2 <input type="text" id="txt2" /> <br /> <button id="btncalc">calculate difference</button> <div id="result"></div> </div> <script> function test() { document.getelementbyid('re').innerhtml = ''; var n1 = new number(document.getelementbyid('od1').value); var n2 = new number(document.getelementbyid('od2').value); if (isnan(n1) || isnan(n2)) { alert('one or both inputs not number'); } else { document.getelementbyid('re').innerhtml = n1 - n2; } } window.onload = function() { document.getelementbyid('od').onclick = test; } </script> <div> enter value 1 <input type="text" id="od1" /> <br />enter value 2 <input type="text" id="od2" /> <br /> <button id="od">calculate difference</button> <div id="re"></div> </div> </body>
the problem first form isnt working , second working. on site want many of these calculator, dont know why not working. gradefull if me find result.
write javascript code in 1 script tag. try following code
<body> <script> function calcresult(){ document.getelementbyid('result').innerhtml = ''; var num1 = new number(document.getelementbyid('txt1').value); var num2 = new number(document.getelementbyid('txt2').value); if(isnan(num1) || isnan(num2)){ alert('one or both inputs not number'); } else { document.getelementbyid('result').innerhtml = num1 * num2; } } function test(){ document.getelementbyid('re').innerhtml = ''; var n1 = new number(document.getelementbyid('od1').value); var n2 = new number(document.getelementbyid('od2').value); if(isnan(n1) || isnan(n2)){ alert('one or both inputs not number'); } else { document.getelementbyid('re').innerhtml = n1 - n2; } } window.onload=function(){ document.getelementbyid('btncalc').onclick = calcresult; document.getelementbyid('od').onclick = test; } </script> <div> enter value 1 <input type="text" id="txt1" /><br /> enter value 2 <input type="text" id="txt2" /><br /> <button id="btncalc">calculate difference</button> <div id="result"></div> </div> <div> enter value 1 <input type="text" id="od1" /><br /> enter value 2 <input type="text" id="od2" /><br /> <button id="od">calculate difference</button> <div id="re"></div> </div> </body>
Comments
Post a Comment