dfred
07-11-2001, 03:49 PM
Here is the problem. I have a month select box and a year select box. these are part of a loop. when I submit the page, there could be 1 or many month and year.
ex:
after submit
month1=jan
month2=feb
year1-2000
year2=2001
I neet to cancatinate month1-year1 and month2-year2
then I need to many a list out of these.
I saw there was a join function but not sure if that is a one-dim array only or can it work with two 1d arrays or one 2d array.
can anyone shed some light on this for me?
DAN
piglet
07-11-2001, 04:39 PM
Hi dfred,
Joining arrays {1,2,3} and {a,b,c} would give you and array of {1,2,3,a,b,c}...I'm not sure that's what you want.
Are you after something like this?
<html><body><script>
array1 = new Array("month1", "month2","month3");
array2 = new Array("year1", "year2","year3");
joinarray = new Array();
for (i=0; i<array1.length; i++)
joinarray[i]=array1[i]+' '+array2[i];
//then joinarray contains:
for (i=0; i<joinarray.length; i++)
alert(joinarray[i]);
</script></body></html>
dfred
07-11-2001, 04:58 PM
here is my code with a combo of cold fusion and your JS:
<CFSET tempAlphamonth = 0>
<CFSET tempAlphayear = 0>
<CFSET aPackmonthArray = ArrayNew(1)>
<CFSET aPackyearArray = ArrayNew(1)>
<CFSET ArrayClear(aPackmonthArray)>
<CFSET ArrayClear(aPackyearArray)>
<!--- <CFLOOP INDEX="i" FROM="1" TO="#i#"> --->
<cfset loopcounter = "1">
<cfloop list="#form.kit_number#" index="r">
<!--- <input type="hidden" name="date#r#"> --->
<cfset month=Evaluate("form.comp_month" & loopcounter)>
<CFSET tempAlphamonth = ArrayAppend(aPackmonthArray, month)>
<cfset year=Evaluate("form.comp_year" & loopcounter)>
<CFSET tempAlphayear = ArrayAppend(aPackyearArray, year)>
<cfset loopcounter = loopcounter + 1>
</cfloop>
<script>
sPackDateArray = new Array();
for (i=0; i < aPackmonthArray.length; i++)
sPackDateArray[i]=aPackmonthArray[i]+' '+aPackyearArray[i];
//the joinarray contains
for (i=0; i < sPackDateArray.length; i++)
alert(sPackDateArray[i];
</script>
First I was trying to populate both arrays from the form.comp_month and form.comp_year using ArrayAppend. if that worked correctly and both arrays were populated, then I thought your code may work. Then I thought I could just output the sPackDateArray to the screen to see the concatinated values. This did not work...an error displayed on the output. i am not sure the the arrays are populating.
hope this helps you and anyone.
DAN
dfred
07-12-2001, 03:14 PM
Stephence is on the right track...actually that is exactly what I want. the only thing I need now is how to take the hard coded arrays and make them variable...depending on how many months and dates there are. there could be one or there could be 20 or more. I don't know how to create an array where the number of dates and years are not known but are variable.
Can someone help me with this...Please?
DAN
piglet
07-12-2001, 03:19 PM
Sorry dfred,
I've no idea what this coldfusion code is all about - does it get converted to javasript at some point - if so - could you post that instead?
dfred
07-12-2001, 04:01 PM
Sorry...don't worry about the code I posted...the code you gave me strickly js is exactly what I need. I just need to pass form variables for month and year into two seperate arrays.
I could have one or 3 or 5 or 20 ect months and years.
Don't worry about cold fusion.
I cannot seem to find anybody that has had a question about populating an array from forms that vary in amount.
does that make sense?
I hope
DAN
vBulletin® v3.6.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.