jquery - Auto calculation using javascript -
<html> <head> <meta charset="utf-8"> <title></title> <script> var form = document.forms.myform, qty = form.qty, cost = form.cost, output = form.textbox; window.calculate = function () { var q = parseint(qty.value, 10) || 0, c = parsefloat(cost.value) || 0; output.value = (q * c).tofixed(2); }; </script> </head> <body> <form action="caltest.php" method="post" name="myform" onkeyup="calculate()"> <label>num of pax :</label> <input type="text" name="qty" /> <input type="hidden" name="cost" value="700" /> <br/> <lable>total price: </lable> <input type="text" name="textbox" /> </form> </body> </html> i doing simple calculation.not getting output.
when var form = document.forms.myform executed, there no <form name="myform" ...yet.
simplest (though maybe not sophisticated) solution move <script> block <head> after form code.
Comments
Post a Comment