javascript - How to append json values to html[value] -


i have json this. how append json values html input values.

    [{"user_id":"180",     "firstname":"anandhsp",     "lastname":"sp",     "email":"xyz@gmail.com",     "mobile":"9000000000",     "gender":null,     "hashcode":"2xxg3dfyuxjo9c4ovaww",     "username":"anandhsp21",     "password":"64c20f8bb630eb5cb329fdd609c807b7:j6",     "emailverify":"true",     "company_name":"xxx",     "address":"chennai",     "city":"chennai",     "state":"tamilnadu",     "pincode":"637001",     "phone":"1234567890",     "website":"hello",     "nature":"hello",     "no_employe":"23",     "year":"2015",     "type":"proprietor",     "authorized_person":"anandh sp",     "status":"",     "created":"2015-06-26 10:48:09",     "modified":"2015-06-11 11:24:39",     "logdate":"2015-06-26 05:18:09",     "lognum":"3",     "reload_acl_flag":"0",     "is_active":"1",     "extra":"n;",     "rp_token":null,     "rp_token_created_at":null,     "app_name":"",     "api_key":""}] 

html code

<div id="register_form" class="fieldset subgroupregister_form"> <div class="hor-scroll"> <table class="form-list" cellspacing="0"> <tbody> <tr class="tr_tag"> <tr class="tr_application_id"> <tr class="tr_customer_id"> <tr class="tr_company_name"> <tr class="tr_address"> <td class="label"> <td class="value"> <input id="address" class=" input-text required-entry" type="text" value="" name="address"> </td> </tr> <tr class="tr_city"> <tr class="tr_state"> <tr class="tr_pincode"> <tr class="tr_mobile"> <tr class="tr_phone"> <tr class="tr_website"> <tr class="tr_nature"> <tr class="tr_no_employe"> <tr class="tr_year"> <tr class="tr_type"> <tr class="tr_authorized_person"> <tr class="tr_status"> </tbody> </table> </div> </div> </div> 

i need append above values input value

for example

<input id="address" class=" input-text required-entry" type="text" value="chennai" name="address"> 

i tried these codes.but did't got output.

jquery('.ac_results ul li').bind('click',function(e)                     {                         var text = $(this).text();                         jquery.ajax({                             type: 'get',                             url: base_url + 'admin/index/user_id',                             data: {email: text},                             datatype:'json',                             success: function (data) {                                 var data = data[0];                                 $('#address').value = data.address;                                 $('#city').value = data.city;                                 $('#state').value = data.state;                                 $('#pincode').value = data.pincode;                                 $('#mobile').value = data.mobile;                                 $('#phone').value = data.phone;                                 $('#website').value = data.website;                                 $('#email').value = data.email;                                 $('#nature').value = data.nature;                                 $('#year').value = data.year;                                 $('#no_employe').value = data.no_employe;                                 $('#type').value = data.type;                                 $('#authorized_person').value = data.authorized_person;                               }                         });                     }); 

thanks in advance

try val() function:

$('input').val(obj.item); 

check following example

var obj = { test: 'test' }  $('#add').on('click', function() {    $('#inp').val(obj.test);  });  $('#res').on('click', function() {    alert($('#inp').val());  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <input id="inp" type="hidden" />  <button id="add">add value</button>  <button id="res">show input</button>


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -