Addressing form fields in a loop

A

Andrew Banks

I'm using the following code to fill in data in 52 form fields but I think
I've got a problem when I'm trying to concatenate my variables with the
names of form fields. Can anyone help?

var ThursArray = new
Array("01-01-04","08-01-04","15-01-04","22-01-04","29-01-04","05-02-04","12-
02-04","19-02-04","26-02-04","04-03-04","11-03-04","18-03-04","25-03-04","01
-04-04","08-04-04","15-04-04","22-04-04","29-04-04","06-05-04","13-05-04","2
0-05-04","27-05-04","03-06-04","10-06-04","17-06-04","24-06-04","01-07-04","
08-07-04","15-07-04","22-07-04","29-07-04","05-08-04","12-08-04","19-08-04",
"26-08-04","02-09-04","09-09-04","16-09-04","23-09-04","30-09-04","07-10-04"
,"14-10-04","21-10-04","28-10-04","04-11-04","11-11-04","18-11-04","25-11-04
","02-12-04","09-12-04","16-12-04","23-12-04","30-12-04");

function SetDates(ArrayToUse){
for (i=0; i < ArrayToUse.length; i++){
//alert(ArrayToUse);
//alert("I is " + i + " Thurs array is " + ThursArray);
document.add_record_form.date + i + .value = ArrayToUse;
}
}
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in Andrew Banks <[email protected]
k> posted at Wed, 19 Nov 2003 15:01:11 :-
var ThursArray = new
Array("01-01-04","08-01-04","15-01-04","22-01-04","29-01-04","05-02-04","12-
02-04","19-02-04","26-02-04","04-03-04","11-03-04","18-03-04","25-03-04","01
-04-04","08-04-04","15-04-04","22-04-04","29-04-04","06-05-04","13-05-04","2
0-05-04","27-05-04","03-06-04","10-06-04","17-06-04","24-06-04","01-07-04","
08-07-04","15-07-04","22-07-04","29-07-04","05-08-04","12-08-04","19-08-04",
"26-08-04","02-09-04","09-09-04","16-09-04","23-09-04","30-09-04","07-10-04"
,"14-10-04","21-10-04","28-10-04","04-11-04","11-11-04","18-11-04","25-11-04
","02-12-04","09-12-04","16-12-04","23-12-04","30-12-04");

Code should have line breaks at intervals, so that it can be posted in
News without corruption.

No need to list those; it is way enough to calculate all the Thursdays
in a year (and much less annoying if you find they should be Tuesdays);
see below. Test

function DoThu(Y) {
var D = new Date(Y, 0, 1).getDay() // Jan 1, Sun=0..Sat=6
for (D = new Date(Y, 0, 1 + (4+7-D)%7) ; // 4 = Thu
D.getFullYear()==Y ;
D.setDate(D.getDate()+7) ) document.writeln(D, '<br>')
}

DoThu(2004)

change the last 7 to, say, 777, and do
for (j=2000; j<2030; j++) DoThu(j)
to check the start-up logic for ample years.

Then replace the write with a suitable action.

You say 52 fields; there are 53 Thursdays next year.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top