Jquery, calculate html table rows with same class? -
i building invoice grails, , dynamical calculation using jquery.
i don't know, may not solution , not fit in javascript. may me, here go:
<thead> <tr> <g:sortablecolumn style="width: 20px" property="id" title="${message(code: 'packet.id.label', default: 'id')}" /> <g:sortablecolumn style="width: 10px" property="anzahl" title="${message(code: 'packet.anzahl.label', default: 'anzahl')}" /> <th><g:message style="width: 250px" code="packet.artikel.label" default=" artikel " /></th> <th><g:message code="packet.artikel.label" default=" steuer in % " /></th> <th><g:message code="packet.artikel.label" default=" preis pro stück in € " /></th> <th><g:message code="packet.artikel.label" default=" preis gesammt in € " /></th> </tr> </thead> <tbody> <g:each in="${packetinstancelist}" status="i" var="packetinstance"> <tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> <td><g:link controller="packet" action="show" id="${packetinstance.id}">${fieldvalue(bean: packetinstance, field: "id")}</g:link></td> <td><input name="q" class="st" type="text" style="background-color:transparent;border:0px solid white;" value="${fieldvalue(bean: packetinstance, field: "anzahl")}" onclick="if (this.value=='search') {this.value = '';}" readonly="true"/> <!-- ${fieldvalue(bean: packetinstance, field: "anzahl")} --> </td> <td nowrap>${fieldvalue(bean: packetinstance, field: "artikel")}</td>
that creates html many rows
<tr class="even"> <td><a href="/test/packet/show/17">17</a></td> <td><input name="q" class="st" type="text" style="background-color:transparent;border:0px solid white;" value="1,222" onclick="if (this.value=='search') {this.value = '';}" readonly="true"/> <!-- 1,222 --> </td> <td nowrap> blueray,arthouse </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="input-steuer" value="19"/> </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="input-value" /> </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="output-value" readonly /> </td> </tr> <tr class="odd"> <td><a href="/test/packet/show/18">18</a></td> <td><input name="q" class="st" type="text" style="background-color:transparent;border:0px solid white;" value="100" onclick="if (this.value=='search') {this.value = '';}" readonly="true"/> <!-- 100 --> </td> <td nowrap> blueray,arthouse </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="input-steuer" value="19"/> </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="input-value" /> </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="output-value" readonly /> </td> </tr> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="input-steuer" value="19"/> </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="input-value" /> </td> <td> <input type="text" style="background-color:transparent;border:0px solid white;" class="output-value" readonly /> </td> </tr> </g:each>
as can see these rows have same classes.
here jquery code:
$(document).ready(function() { $(".input-value").keyup(function() { // var output = $(".output-value"); var test = 0; $('.input-value').each(function() { var value = parsefloat($(this).val()); var value3 = parsefloat($(".st").val()); var value2 = parsefloat($(".input-steuer").val()); //output.val(((value - value * value2/100)*value3).tofixed(2)); score = ((value - value * value2/100)*value3); score = score.tofixed(2); //output.val(score); test+=score; }); $(".output-value").val(test); }); });
this calculates first row , not each row, i´d have output every row , sum of outputs, not used javascript...
it feels simple, not me.
thanks time
$(".input-value").keyup(function() { var value = parsefloat($(this).val()); var value2; var value3;var temp=0;var temp1 = 0; $(this).parent().siblings().each(function() { if ($(this).children().hasclass('input-steuer')) { value2 = $(this).children().val(); } if ($(this).children().hasclass('st')) { value3 = $(this).children().val(); } }); score = ((value - value * value2 / 100) * value3); $(this).parent().next('td').children('.output-value').val((score).tofixed(2)); $('.output-value').each(function(){ temp1 = $(this).val(); alert(temp1); if(temp1 == 'nan' || temp1 == '') { temp1 = 0.0; } temp = parsefloat(temp) + parsefloat(temp1); }); $('#wholesum').val(temp.tofixed(2)); });
have nice day!
Comments
Post a Comment