0

Hi guys need some help here.

I don't know why but it doesn't read the value.

This is to be runned by Property.

function calculate_form_opap(op_id,oca_id,ocp_id) {
    var propertiesintotal=0;
    var total=0;
    var completo='';
    var completo_count = op_id+'_'+oca_id;
    propertiesintotal = Number(document.getElementById('propertiesintotal_'+op_id+'_'+oca_id).value);
    propertiesintotal=propertiesintotal-1;

    for (y=0; y<=propertiesintotal; y++){
        completo=op_id+'_'+oca_id+'_'+ocp_id+'_'+y;
        alert(completo);
        
        //valor = document.getElementById('property_total_'+completo).value;
        
        valor = $("#property_total_"+completo).val();
        
        if(!valor){
            valor=0;
        }
        
        total = (Number(total) + Number(valor));
        alert(total);
    }

    $('#order_qty_total_'+completo_count).val(total);
    $('#po_qty_'+completo_count).val(total*Number($('#masterq_'+op_id).html()));
    $('#total_'+completo_count).val((total*Number($('#packprice_'+op_id).html())).toFixed(2));

}
And give me:
document.getElementById(
[Break on this error] valor = document.getElementById('property_total_'+completo).value;

I was also trying using jQuery:

valor = $("#property_total_"+completo).val();

It gets the value! But the thing is that if I insert a new value inside another input, it doesn't read the previous value anymore.

See image here just to have a feel of what im talking,

[IMG]http://www.drosendo.com/jserror.jpg[/IMG]

Example: I put 4 in Black / Blue - Medium input box
Result is: 0| 4 | 0 | 0

Then i put the 5 in Black / Blue - Large input box
Result: 0| 0| 5 | 0

The result should be:
0 | 4 | 5 | 0

Giving me total = (Number(total) + Number(valor); result 9

Please help.

Edited by ALFA-FOXTROT: n/a

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by ALFA-FOXTROT
0

Solved using jquery .each object

function calculate_form_opap(op_id,oca_id) {
    $(document).ready(function() {
        var total=0;

        var completo_count = op_id+'_'+oca_id;


        $("input[name*='property_total_"+completo_count+"']").each(function() {
            
            valor=$(this).val();

            total = (Number(total) + Number(valor));
        })



        $('#order_qty_total_'+completo_count).val(total);
        $('#po_qty_'+completo_count).val(total*Number($('#masterq_'+op_id).html()));
        $('#total_'+completo_count).val((total*Number($('#packprice_'+op_id).html())).toFixed(2));

    });

}

Any way don't know why it didn't get the previous number.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.