Jump to content

Need help with javascript arrays.


iPixel

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.