Jc John
Jc John

Reputation: 1859

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) {
         $.ajax({
          url : "<?php echo site_url('manager/profile/userDetails/')?>/" + id,
          type: "GET",
          dataType: "JSON",
          success: function(data) {
                $('#fname').html(data['user_fname']);


          },
          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">

Upvotes: 0

Views: 526

Answers (1)

gavgrif
gavgrif

Reputation: 15509

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

 $('#fname').val(data['user_fname']);

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

Upvotes: 2

Related Questions