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 {
function edit()
{
$this->load->view('ncmr_edit');
}
}
function get_ncmr_by_id()
{
// GET VALUES BY ID
$id = $this->input->post('idncmr');
$data['ncmr'] = $this->model->get_ncmr_by_id($id);
print json_encode($data);
}
View ncmr_edit
Code:
<html>
<head>
<script href="jquery" >
<script>
$(document).ready(function () {
$("#searchbtn").click( function()
{
var ncmrid = $('#search').val();
$.ajax({
url: "http://localhost/ncmr/index.php/ncmr/get_ncmr_by_id",
async: false,
type: "POST",
data: "idncmr="+ncmrid,
dataType: "html",
success: function(data) {
$('#form').html(data);
}
})
});
});
</script>
</head>
<body>
<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">
<div>
</body>
</html>
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.