Click here to Skip to main content
15,900,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
var res = "";
    var arrayLength = resultArr.length;
    for (var i = 0; i < arrayLength; i++) {

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

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

       


    }

}


how could i invoke this code
C#
$("#result).click(function () {

           window.location.href = resultArr[i].value;
       });



With the code in top?


UPDATE
====================

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 };



    });



UPDATE NEW
==========================
C#
var res = "";

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

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

       var x = document.createElement("INPUT");
       x.setAttribute("type", "hidden");
       document.body.appendChild(x);
       x = resultArr[i].value;

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


       var labelID;

       $('#result').click(function (x) {
           labelID = $(this).attr('for');
           $('#result' + labelID).trigger('click');
           alert("klickad");
           window.location.href = x;
       });
Posted
Updated 13-Jan-15 2:57am
v3
Comments
ZurdoDev 13-Jan-15 8:12am    
I don't understand your question. You have "result" which is some html object and you set the html and then want that when it's clicked to do something? I'd suggest wrapping your "result" in a div and put the click function on the div.
Kurac1 13-Jan-15 8:22am    
result is a dig tag, i display title and url to the title, when click on title go to url
ZurdoDev 13-Jan-15 8:34am    
So, what is your question then?
Kurac1 13-Jan-15 8:36am    
Its in the top pls read.
ZurdoDev 13-Jan-15 8:37am    
I did read and it is not clear at all. If you want help, then please be clear.

1 solution

You'll need to create a hidden field on the page

XML
<asp:hiddenfield runat="server" id="hdnReturnVal"/>


Then you store the return value in that field:
JavaScript
$("#hdnReturnVal").val(returnVal);


and then you can access it in the click function
JavaScript
var url = $("#hdnReturnVal").val();
...
 
Share this answer
 
v2
Comments
Kurac1 13-Jan-15 9:04am    
Alright thanks could u please se me update code on this link http://www.codeproject.com/Questions/864911/Best-way-to-display-data-in-javascript-jquery?arn=0
ZurdoDev 13-Jan-15 9:06am    
I'm not sure what you mean. I gave you sample code. You should be able to do what you need to with it.
Kurac1 13-Jan-15 9:08am    
Yes but the link that i have typed to you in other question/ problem i have

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