2016-09-15 2 views
1

Ich wollte einen Eingabewert anhand der Auswahl aus einer Combobox im Codezeichner ändern. Ich habe versucht, es zu codieren, aber es gibt nichts, was angezeigt werden könnte. Hier ist mein Code in meinem Controller .....Eingabewert mit Ajax im Codezeichner ändern

function fill_info() 
{ 
    // retrieve the group and add to the data array 
    $group_id = $this->input->post('group_id'); 
    $data = "0.00"; 
    if($group_id) 
    { 
     $this->load-model('Base_amount_setting_model'); 
     $baseamount = $this->Base_amount_setting_model->getbaseamount($group_id); 
     $data .= $baseamount; 
     echo $data; 
    } 
    else 
    { 
     echo $data; 
    } 
} 

Und in meinem Base_amount_setting_model da diese Methode ist ....

function getbaseamount($group_id) 
{ 
    $this->db->where('group_id',$group_id); 
    $baseamount = $this->db->get('base_amount_setting')->row()->amount; 
    if($baseamount -> num_rows() == 1) 
    { 
     return $baseamount->result(); 
    } 
} 

Und es meiner Meinung nach sieht die Ajax so. ....

<script> 
    $(document).ready(function() 
    { 
     $("#group_id").change(function() 
     { 
      var group_id = $("#group_id").val(); 
      $.ajax({ 
       type : "POST", 
       url : "<?php echo base_url('payment/fill_info'); ?>", 
       data : "group_id=" + group_id, 
       success: function(data) 
       { 
        $("#base_amount").html(data); 
       } 
      }); 
     }); 
    }); 
</script> 

und schließlich wie dies meine Form ist ...

<div class="control-group"> 
    <label class="control-label" for="select01">Group Id </label> 
    <div class="controls"> 
     <select class="chzn-select" name="group_id" id="group_id" placeholder="Group Id" value="<?php echo $group_id; ?>"> 
      <option></option> 
      <?php 
      if (count($groups)) { 
       foreach ($groups as $list) { 
        echo "<option value='". $list['group_id'] . "'>" . $list['group_name'] . "</option>"; 
       } 
      } 
      ?> 
     </select> 
     <label for="int" class="err"><?php echo form_error('group_id') ?></label> 
    </div> 
    <input class="input-xlarge disabled" id="base_amount" name="base_amount" type="text" placeholder="Base Amount" disabled=""> 
    <input class="input-xlarge disabled" id="total_members" type="text" placeholder="Total Members" disabled=""> 
</div> 

Vielen Dank!

$("#base_amount").html(data); 

zu

$("#base_amount").val(data); 

Eigentlich .html REPLCE:

+0

sollten Sie $ ändern ("# base_amount"). Val (data); –

Antwort

0

ich bin wirklich neugierig - aber ich denke, Ihr Modell etwas zurückgeben tut versuchen die folgende

function getbaseamount($group_id) 
{ 
    $query = $this->db 
     ->where('group_id',$group_id) 
     ->get('base_amount_setting'); 

    if ($query->num_rows() == 1) 
    { 
     $obj = $query->row(); 
     return $obj->amount; 
    } 
} 

und wie andere vorgeschlagen

Änderung Ihrer Skriptcode

$("#base_amount").val(data); 

und Ihre Controller-Funktion sollte wie folgt aussehen:

function fill_info() 
{ 
    // retrieve the group and add to the data array 
    $group_id = $this->input->post('group_id'); 
    $data = "0.00"; 
    if($group_id) 
    { 
     $this->load-model('Base_amount_setting_model'); 
     $baseamount = $this->Base_amount_setting_model->getbaseamount($group_id); 
     echo $baseamount; 
    } 
    else 
    { 
     echo $data; 
    } 
} 
2

Änderung dieser $("#base_amount").html(data); zu $("#base_amount").val(data);

+0

Das war hilfreich. – Kirubel

1

Eigentlich, wenn Sie Ihren Wert nach Ajax in data Objekt getroffen bekommen dann diese nur ändern das HTML ändert nicht das Wert.

Verwandte Themen