iPixel Posted January 4, 2010 Share Posted January 4, 2010 So via php / js call i pass a string that looks like so... onclick="UnfoldTree(<?php echo $FNLIST; ?>)" $FNLIST contains a string that looks like this... '6263,2894,4231,2937,4846,4790,2909,2852,4875,4881,4801,2931,4831,4832,4833,4778,2878,4809,4883,4061,4869,2941,7134,' No now here's my JS, please tell my why i get this error... Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Timestamp: Mon, 4 Jan 2010 18:54:09 UTC Message: Object doesn't support this property or method Line: 228 Char: 3 Code: 0 URI: http://path/tap.php The JS Code : function UnfoldTree(divArray) { alert(divArray); var myArray = divArray.Split(','); for(i in myArray) { document.getElementById( i ).style.display = 'block'; } } Quote Link to comment https://forums.phpfreaks.com/topic/187152-need-help-with-javascript-arrays/ Share on other sites More sharing options...
Psycho Posted January 4, 2010 Share Posted January 4, 2010 I suspect the problem is that the "Object doesn't support this property or method" I suspect you are wanting to reference the objects with IDs the same as the values in your array? When you do a For...In within JavaScript, the FOR value is not the value in the array - it is the index of the value. I think what you want to do is this: function UnfoldTree(divArray) { alert(divArray); var myArray = divArray.Split(','); for(index in myArray) { document.getElementById( myArray[index] ).style.display = 'block'; } } Quote Link to comment https://forums.phpfreaks.com/topic/187152-need-help-with-javascript-arrays/#findComment-988296 Share on other sites More sharing options...
iPixel Posted January 4, 2010 Author Share Posted January 4, 2010 Still get that same error, and your assumption is correct. Somewhere on the page i have these ID's generated that store the data, and they are not displayed by default, and clicking that 1 button will show them all. If you know any other way to do this other then what i'm trying please feel free to show me, im open to all ideas. Quote Link to comment https://forums.phpfreaks.com/topic/187152-need-help-with-javascript-arrays/#findComment-988307 Share on other sites More sharing options...
iPixel Posted January 4, 2010 Author Share Posted January 4, 2010 Got it! function UnfoldTree(divArray) { alert(divArray); var fnarray = divArray.split(","); for(i in fnarray) { alert(fnarray[i]); // Show divs isntead. } } it's because the .Split was with initial capitol letter instead of .split. DOH !!! i hate case sensitive programming. Quote Link to comment https://forums.phpfreaks.com/topic/187152-need-help-with-javascript-arrays/#findComment-988321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.