Search code examples
phpjqueryformsbuttonfill

How to get text from input field without submiting form in php


I am using this code

$('.calc').blur(function () {
    var sum = 0;
    $('.calc').each(function() {
        if($(this).val()!="")
         {
            sum += parseFloat($(this).val());
         }

    });
        $('.full_calc').val(sum);
});

to fill dynamically input and I want to get its data dynamically (changed in every new input filled) in php variable and use it for other calculations without a submit button. Can I do this?


Solution

  • try this, change jquery file name like you have there :

    <html>
    <head>
        <title>On Change</title>
        <script type="text/javascript" src="jquery-1.9.1.js"></script>
        <script>
            function sum(){
                $("#n3").val(eval($("#n1").val())+eval($("#n2").val()));
            }
            $(document).ready(function(e) {
                $("#n1").change(function(){
                    sum();
                });
                $("#n2").change(function(){
                    sum();
                });
            });
    
        </script>
    </head>
    <body>
        N1 :<input type="text" name="n1" id="n1" value="0" /><br>
        N2 :<input type="text" name="n2" id="n2" value="0" /><br>
        N3 :<input type="text" name="n3" id="n3" value="0" />
    </body>
    </html>