Sum in PHP with HTML Form using Jquery -
i new jquery , want create very simple page learn bit about. trying make form sends values php. php sum , returns results. jquery show in page, dynamically.
this html , javascript:
<html> <head> <title>null</title> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("form1").change(function() { $.get("requisit.php", {a1: $("#a1").html(), a2: $("#a2").html()}, function(data) { $(".results").empty().html(data); }); return false; }); }); </script> </head> <body> <form name="form1"> <input type="text" name="a11" id="a1"><br/> <input type="text" name="a22" id="a2"> </form> <div class="results"> answer is: </div> </div> </body> </html>
this php:
<?php $a1 = $_get['a1']; $a2 = $_get['a2']; $sasa = $a1+$a2; echo $sasa; ?>
ajax not displaying results. that's problem. trying make ajax detect modification , show results not work , dont know why.
thank you!
<html> <head> <title>null</title> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".sum").keyup(function() { totalamount=0; $('.sum').each(function() { if($(this).val()!=""){ totalamount += parsefloat($(this).val()); } }); $(".results").html(totalamount ); }); }); </script> </head> <body> <form name="form1"> <input type="text" name="a11" class="sum" id="a1"><br/> <input type="text" name="a22" class="sum" id="a2"> </form> <div class="results"> answer is: </div> </div> </body> </html>
you can try code: need take common class of each textarea box , use $('.sum').each(function()