Click here to Skip to main content
15,892,805 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var resultArr = ["A","B","C"];

    var arrayLength = resultArr.length;
    for (var i = 0; i < arrayLength; i++) {

        res = res + resultArr[i].label + "<br /> ";



       $("#result").html(res);



    }


}


HTML
<a id="result"></a> 


My data if i example have 3 items the 3 items are displayed in same line as a link but i want to split every item and display 1 a link to every item and not all the same on line?


I want to clicken the title that are displayed go to that URL.
Right now if i in my input box type Sub the count in my for loop gets 3 items and displays them like this but my titles are now hyper links its just 1 hyperlink all over the titles
so when hover over the titles its gets underline like all the titles are in a same a href,
but i want to display them like this

ASub1
Sub1
Sub2


ASub1 (link for this page)
Sub1 (link for this page)
Sub2 (link for this page)

Right now it displays

ASub1 (link for this page
Sub1
Sub2 )
Posted
Updated 13-Jan-15 3:14am
v4

1 solution

Hi,

There is small change in your code. In for loop, you are using text property of div element, which takes only last item from array every time. In every count of for loop, div text is override that's why only last item from array display. You should use append rather that text.

I made some changes in your code :

C#
function successHandler(data) {

        var jsonObject = JSON.parse(data.body);
        var dataArr = $.makeArray(jsonObject.d.results);
        var resultArr = $.map(dataArr, function (item) {

            return { label: item.Title, value: item.Url };

        });

        var arrayLength = resultArr.length;
        for (var i = 0; i < arrayLength; i++) {
            $("#result").append(resultArr[i].label + " " + resultArr[i].value + "<br />");
        }
}

Check this code.
Thank you
 
Share this answer
 
Comments
Kurac1 13-Jan-15 7:38am    
Alright, it works but i have not changed my to an a href link if i have 3 items it display all 3 items in same line as a link but i want for ex Item1 1 link, Item2 1 link, Item3 1 link, right now its Item1 Item2 Item3 1 link
Kurac1 13-Jan-15 7:46am    
I have updated my question and my code in the top
JR009 13-Jan-15 8:08am    
I cant't understand, what are you trying to say. Can you show a sample output formate?
Kurac1 13-Jan-15 8:14am    
i will update again
Kurac1 13-Jan-15 9:27am    
You said that i only get display 1 item in a div, but i want to display more items then 1 but not as same value
I dont wont to display [object],[object],[object] like this because then if i click the link it 3 links there , i want to have on link per object when clicking it

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