470,614 Members | 1,458 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Addressing form fields in a loop

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[i]);
//alert("I is " + i + " Thurs array is " + ThursArray);
document.add_record_form.date + i + .value = ArrayToUse[i];
}
}
Jul 20 '05 #1
2 2248
"Andrew Banks" <ba****@nospamblueyonder.co.uk> writes:
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?


Yep, the FAQ is your friend.
<URL:http://jibbering.com/faq/#FAQ4_39>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
JRS: In article <XA*********************@news-text.cableinet.net>, seen
in news:comp.lang.javascript, Andrew Banks <ba****@nospamblueyonder.co.u
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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Colin Steadman | last post: by
3 posts views Thread by jcrouse | last post: by
7 posts views Thread by Chuck Anderson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.