In my registration form I have a field called s_id. when i will input the s_id a field name s_name will be filled automatically. actually s_id is id of a old user and s_name is his name. So they are in database like id and name being used as s_id and s_name for a new user.
Here is my view code
<input type="text" name="s_id" id="s_id" onkeyup="get_user_name('id');" />
<input type="text" name="s_name" id="s_name" />
<script type="text/javascript">
function get_user_name(id){
var data = $('#'+id).val();
jQuery.ajax({
url: "<?php echo site_url('welcome/test');?>",
type: "POST",
data: { id:Data },
cache: false,
dataType: "text",
success: function(data) {
$("#name").val(data);
}
});
}
</script>
What should be the controller and model function structure for this job?
In controller: You just need to echo the result.
Like this: