0

I want to move the name attribute, to be a hidden value (not id), but ... stored in the database that is still id

<div class="form-group col-md-4">
    <select name="id_cs" id="pakyu" class="form-control select2" style="width: 100%;" onchange="ganti();">
        <option value="0">-PILIH-</option>
        <?php foreach($datacs->result() as $row):?>
        <option value="<?php echo $row->id_cs;?>"><?php echo $row->nama_cs;?></option>
        <?php endforeach;?>

        <input type="hidden" id="csnya" name="nama_cs">
    </select>
</div>

jquery

function ganti() {
    var reg = $('#pakyu option:selected').val();
    $('#csnya').val(reg);
}
Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
Tito
  • 17
  • 6

1 Answers1

0

Do some changes like this:

<div class="form-group col-md-4">
    <select name="id_cs" id="pakyu" class="form-control select2" style="width: 100%;" onchange="ganti();">
        <option value="0">-PILIH-</option>
        <?php foreach($datacs->result() as $row):?>
        <option value="<?php echo $row->id_cs;?>"><?php echo $row->nama_cs;?></option>
        <?php endforeach;?>
    </select>
    <input type="hidden" id="csnya" name="nama_cs" value=""> <!--moved this out from select tag -->
</div>

jQuery:

function ganti() {
    var reg = $('#pakyu option:selected').text();  // Use text function
    $('#csnya').val(reg);
}
Himanshu Upadhyay
  • 6,438
  • 1
  • 16
  • 32