Jc John Jc John - 10 months ago 71
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">

Answer Source

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.