<table class='table table-stripped table-hover table-condensed table-bordered'>
    <thead>
        <tr>
            <th> <h4>Kurir</h4></th>
<th> <h4>Jenis Layanan</h4> </th>
<th > <h4>Tarif</h4> </th>
<th></th>
</tr>
</thead>
<tbody>
    <?php
    for ($i = 0; $i < count($query['rajaongkir']['results']); $i++) {
        for ($j = 0; $j < count($query['rajaongkir']['results'][$i]['costs']); $j++) {
            ?>
            <tr>
                <td><strong><?php echo $query['rajaongkir']['results'][$i]['name']; ?></strong><p><small><?php echo $query['rajaongkir']['results'][$i]['costs'][$j]['description']; ?></small></td>
                <td><?php echo $query['rajaongkir']['results'][$i]['costs'][$j]['service']; ?></td>
                <td><?php echo "Rp. " . number_format($query['rajaongkir']['results'][$i]['costs'][$j]['cost'][0]['value']); ?></td>
                <td>
                    <button type="button" onclick="return pilih(<?= $query['rajaongkir']['results'][$i]['costs'][$j]['cost'][0]['value'] ?>)" class="btn btn-xs btn-info">pilih layanan</button>
                </td>
            </tr>
            <?php
        }
    }
    ?>
</tbody>
</table>

<?php
$citi2 = $this->input->post('city_destination');
$weig = $this->input->post('berat');
$kurir = $this->input->post('kurir');

//echo $citi2 . " " . $weig . " " . $kurir;
?>

<script>
    function pilih(ongkir) {
        $('#shipping').html("");
        $('#total_order').html("");
        var hrg = $('#sub_total').val();        
        $('#shipping').html(addCommas(ongkir));
        $('#shipping_val').val(ongkir);
        var totalBayar = parseInt(hrg) + parseInt(ongkir);
        $('#total_order_val').val(totalBayar);
        $('#total_order').html(addCommas(totalBayar));
    }

    function addCommas(nStr) {
        nStr += '';
        var x = nStr.split('.');
        var x1 = x[0];
        var x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        return x1 + x2;
    }

</script>
