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

       $("#result").text(resultArr[i].label);

       $("#result").click(function () {
           window.location.href = resultArr[i].value;
       }




      )



I display a name and the name also has a value with a link i want when u click the name thats a href go to that page

i get this error right now:

Error: Unable to get property 'resultArr' of undefined or null reference
Posted
Comments
Kornfeld Eliyahu Peter 13-Jan-15 5:43am    
In your code there is no such thing resultArr - so it is obvious you get an error of 'undefined'...
Sinisa Hajnal 13-Jan-15 6:36am    
You're binding to click handler to #result. And bind it again and again. You should either have arrayLength elements and bind each to single click handler...or bind only one result and in click handler select relevant url and redirect.

1 solution

Try it, and let me know if anything else you require.
////JQuery////
C#
var resultArr=[{"label":"Google","value":"https://www.google.co.in/"},{"label":"Yahoo","value":"http://www.yahoo.com/"},{"label":"Rediff","value":"http://www.rediff.com/"},{"label":"Youtube","value":"http://www.youtube.com/"}];
var arrayLength = resultArr.length;
var str="";
   for (var i = 0; i < arrayLength; i++) {
         str+="<a href='"+resultArr[i].value+"'>"+resultArr[i].label+"</a></br>";
   }
$("#result").append(str);



////HTML//////
XML
<div id="result">
</div>
 
Share this answer
 

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