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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -