Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Inside html view page there is two div.

HTML
<div id="divbindProject" class="col-sm-2"></div>
                           <div id="divbindProjectlist" style="display:none" class="col-sm-3">
                               <div>
                                   <a class="list-group-item active left-menu-head">Projects List</a>

                                   <a href="#" id="idProject" class="list-group-item"></a>

                               </div>
                           </div>


How can I append list of 'proejctname' from json object in to the <a id="idProject" as show below ?

[^]

What I have tried:

JavaScript
$("#btnAddProject").click(function (e) {
    var json = {};

    debugger;
    $.each($('#frmSubmitPremUserProject').serializeArray(), function (i, field) {
        json[field.name] = field.value || '';
    });

    $("#divbindProject").hide();
    $("#divbindProjectlist").show();

    $.each(json, function (i, field) {
        $("#idProject").append(field.name + ":" + field.value + " ");
    });
  
    var str = JSON.stringify(json);
    $("#hdPremUserProject").val(str);

});


After implement this code look like, but here inside list I want to bind list of Projectname from json object:-

[^]

How can I do this? please help me...
Posted
Updated 14-Mar-17 20:35pm
v2

1 solution

use this
for (var i in json) {
             $("#idProject").append(i+ ":" + json[i]+ " ");
         }

instead of
$.each(json, function (i, field) {
       $("#idProject").append(field.name + ":" + field.value + " ");
   });
 
Share this answer
 
Comments
Rajesh Kumar 2013 15-Mar-17 3:34am    
Sir, after implement your code, now its showing all json data. Please look below image. But I want to show only projectname inside <a html.

https://ibb.co/b4aJLa
Karthik_Mahalingam 15-Mar-17 4:00am    
show some sample
Rajesh Kumar 2013 15-Mar-17 4:04am    
Sir, this url showing json content. please look. Is it enough?

https://s7.postimg.org/n81g2vmgb/jsonnn.png

https://ibb.co/b4aJLa
Karthik_Mahalingam 15-Mar-17 4:09am    
what is your expected output
Rajesh Kumar 2013 15-Mar-17 4:15am    
Output is simple. Just show list 'Projectname'from json object. Everytime click on $("#btnAddProject") getting project details from $('#frmSubmitPremUserProject') this form. Then I am adding this json data to Hiddenfield and bind 'Projectname' inside <a each time. This is the plan.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900