• Notice regarding image hosts and attachments. See here.

Javascript: Why doesn't my array of arrays work?

Bes

Bes

Soldato
Joined
18 Oct 2002
Posts
7,318
Location
Melbourne
Hi,

I am trying to create an array of arrays in Javascript to hold data on a set of data from a form of an unknown size. This is what I have so far:
PHP:
   <script>
  $(document).ready(function(){
	var formTypes=new Array("GlobCol","CoOrd");
	var fTWrapper=new Array();
	for ( var i=0, len=formTypes.length; i<len; ++i ){
  	var input= $("input[name^=" + formTypes[i] + "]");
  	var multipleValues = $("input[name^=" + formTypes[i] + "]").val();
		var values=new Array();
		for (x=1; x<=input.length; x++)
		{
   		values[x]=$("input[name^=" + formTypes[i] + x + "]").val();
		}    
	
	 fTWrapper[i]=values;
		$("div").text("For the field type"+ formTypes[i] +" jQuery found.."+ input.length +"."+fTWrapper[1]+" and " +x+ " elements in the array. Last Testing.." + values[5]);
		
	}
  });
  </script>

This works perfectly, except if I replace ftWrapper[1] in the last line with ftWrapper[1][1], I get no output and a script error (At the moment I get the contents of Values seperated with commas)... I have no idea why.

Can anyone tell me where I am going wrong please?

Thanks
 
Last edited:
Hey guys, sorry been away for a few days... thanks for the hints I will look at this again tonight :)
 
The funny thing is that is it printing out all of the elements of the values array as ftwrapper[1] or ftwrapper[0], but it simply is not picking out an individual element.
 
Back
Top Bottom