jquery - realtime update value in form from table -


i have created table calculate grand total of few fields in real time .i have form after table input field named amount ,how can make value updated in real time same value grand total in table. meaning if grand total in table 10 value in form should change 10.

see fiddle: http://jsfiddle.net/hsxkw/48/

html:

<table>     <thead>         <tr>             <th>variable</th>                <th>qty</th>             <th>price</th>             <th>sum</th>         </tr>     </thead>     <tbody>         <tr>             <td>millage</td>             <td><input class='qty' size='1'/></td>             <td class='price'>1.25</td>             <td class='sum'>0</td>         </tr>         <tr>             <td> number of vans</td>             <td><input class='qty' size='1'/></td>             <td class='price'>2.10</td>             <td class='sum'>0</td>         </tr>                 <tr>             <td colspan='2'>total</td>             <td id='total'></td>         </tr>     </tbody> </table> <form action=""> <input name="amount" value="0.00"> </form> 

jquery:

function gettotal(){     var total = 0;     $('.sum').each(function(){         total += parsefloat(this.innerhtml)     });     $('#total').text(total); }  gettotal();  $('.qty').keyup(function(){     var parent = $(this).parents('tr');     var price = $('.price', parent);     var sum = $('.sum', parent);     var value = parseint(this.value) * parsefloat(price.get(0).innerhtml||0);     sum.text(value);     gettotal(); }) 

right after

$('#total').text(total); 

you can

$("form input[name='amount']").val(total); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -