Jc John Jc John - 21 days ago 4x
Javascript Question

ajax passing the json value to html input type text

I want to pass the output of my ajax json to my input type textbox. How can i do it. I have this code but my code doesn't work. here it is

my script :

function getUserDetails(id) {
url : "<?php echo site_url('manager/profile/userDetails/')?>/" + id,
type: "GET",
dataType: "JSON",
success: function(data) {

error: function (jqXHR, textStatus, errorThrown) {
//alert('Error get data from ajax');

my html input type tag :

<input type="text" class="form-control" id="fname" placeholder="First Name">


You need to use .val() to add the value into the input. Try the following:


also you need to ensure that that the input can handle this value and and is expecting.