CodeIgniter Forums

Full Version: Compairing summaries of array inputs form
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]redraw[/eluser]
Dearl All,

I have a problem about validating sum of multiple input form.
this my form :
Code:
<form name="ftranse" id="ftranse" method="post" action="">
<?php $i = 0; ?>
<?php foreach($detail->result() as $rows):?>
    <input type="hidden" name="<?php echo 'trans['.$i.'][master_id]'; ?>" value="<?php echo $rows->master_id; ?>">
    <input type="hidden" name="<?php echo 'trans['.$i.'][tanggal]'; ?>" value="<?php echo $rows->master_id; ?>">
    <input type="hidden" name="<?php echo 'trans['.$i.'][user]'; ?>" value="<?php echo $rows->user; ?>">
    <input type="hidden" name="<?php echo 'trans['.$i.'][no_bukti]'; ?>" value="<?php echo $rows->no_bukti; ?>">
    <input type="hidden" name='jenis' id='jenis' value="<?php echo $rows->jenis; ?>" class='trans[][jenis]'>
    <input type="hidden" name="<?php echo 'trans['.$i.'][awal]'; ?>" value="<?php echo $rows->awal; ?>">

    <input type="text" name="<?php echo 'trans['.$i.'][keterangan]'; ?>" id="<?php echo 'trans['.$i.'][keterangan]'; ?>" value="<?php echo $rows->keterangan;?>"  style='width:45%'>
    <input type="text" name="<?php echo 'trans['.$i.'][nilai]'; ?>" id="<?php echo 'trans['.$i.'][nilai]'; ?>" value="<?php echo $rows->nilai;?>" class='trans[][nilai]'>
<br>
&lt;?php $i++; ?&gt;
&lt;?php endforeach;?&gt;
&lt;/form&gt;

and this is javascript checker before this form send to action

Code:
function edit_master()
{    
    var i = 0;
    var tot = 0;
    jenis = document.getElementsByName('jenis');

while (i <= jenis.length)
{
        var jenis = document.ftranse.jenis[i].value;
        alert(jenis);

    if (jenis =='d')
    {
        var nilaid = document.ftranse.getElementsByClassName('trans[][nilai]');    
        for(var i=0; i < nilaid.length; i++)
         {
             var na1 = parseInt(nilaid[i].value.replace(/,/g,""));
             var tot1 = tot + parseInt(nilaid[i].value.replace(/,/g,""));
            alert('jd =' + jenis);
            alert('tot1 = '+tot1);

         }
    }
                i++

}

while (i <= jenis.length)
{
        var jenis = document.ftranse.jenis[i].value;
        alert(jenis);

    if (jenis =='k')
    {
        var nilaik = document.ftranse.getElementsByClassName('trans[][nilai]');    
        for(var i=0; i < nilaik.length; i++)
         {
             var na2 = parseInt(nilaid[i].value.replace(/,/g,""));
             var tot2 = tot + parseInt(nilaid[i].value.replace(/,/g,""));
            alert('jk =' + jenis);
            alert('tot2 = '+tot2);

         }
    }
                i++

}
    
    
    

        if (tot1 != tot2){
            alert("Not Same, Please check again.");
            }else{    
            var nama = confirm(Are you sure want to update this data?');
            if (nama == true){
                send_form(document.ftranse,"haluser/gl_edit_trans/","#content");
            }else{
                window;
            }
        
        }

}

i want compairing 2 kind of input form..
1. summaries of inputs form which have 'jenis = d'
2. summaries of input form which have 'jens = k'

these inputs form must be balance before they send to database.

please help
thank you

El Forum

[eluser]toopay[/eluser]
Yang tepat sebetulnya dilakukan di Controller. Bentuk array yang mau kamu bandingkan seperti apa?

El Forum

[eluser]redraw[/eluser]
makasih mas udah solved.. Smile