• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How fill input fields with ajax

Hello, I have a question about how to handle this situation.

I'm creating an edit page, I have and input field for the user to type the "ID" of the record I want to modify and a search button, when the user click on the search button I want to populate the form and if anything need to be changed give to the user the option to do that.

Controller ncmr
PHP Code:
class ncmr extends CI_Controller {



       // GET VALUES BY ID
       $id $this->input->post('idncmr');
       $data['ncmr'] = $this->model->get_ncmr_by_id($id);
        print json_encode


View ncmr_edit

<script href="jquery" >

   $(document).ready(function () {
       $("#searchbtn").click( function()
            var ncmrid = $('#search').val();
               url: "http://localhost/ncmr/index.php/ncmr/get_ncmr_by_id",
               async: false,
               type: "POST",
               data: "idncmr="+ncmrid,
               dataType: "html",

               success: function(data) {


<input type="text" placeholder="Search by NCMR ID" id="search" />
<button class="btn btn-default" type="button" id="searchbtn">Search</button>

<br />

<input type="text" name="ncmr_num" value=""/>
<br />

<br />
<hr />
<br />
<div class="form">


So basically I'm showing the results on the ncmr_edit, but I would like to populate the ncmr field with the data from the query.

Make your controller generate the value for the ncmr_num field only. Echo that out, so it will be returned to the Jquery script.
Also give the ncmr_num field an ID, e.g. id="ncmr_num".
Then, in the success part of AJAX, put $('#ncmr_num').val(data);

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.