Addressing form fields in a loop

Discussion in 'Javascript' started by Andrew Banks, Nov 19, 2003.

  1. Andrew Banks

    Andrew Banks Guest

    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;
    }
    }
    Andrew Banks, Nov 19, 2003
    #1
    1. Advertising

  2. "Andrew Banks" <> 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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Nov 19, 2003
    #2
    1. Advertising

  3. JRS: In article <XALub.4818$>, seen
    in news:comp.lang.javascript, Andrew Banks <
    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.
    Dr John Stockton, Nov 20, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AFN
    Replies:
    8
    Views:
    7,692
    =?Utf-8?B?QW5keSBaIFNtaXRo?=
    Jun 16, 2004
  2. Frank Stephan

    Addressing form elements using array

    Frank Stephan, Jan 7, 2004, in forum: Javascript
    Replies:
    11
    Views:
    182
    Laurent Bugnion, GalaSoft
    Jan 9, 2004
  3. wreed
    Replies:
    9
    Views:
    186
    wreed
    Oct 16, 2006
  4. Isaac Won
    Replies:
    9
    Views:
    364
    Ulrich Eckhardt
    Mar 4, 2013
  5. Replies:
    23
    Views:
    495
    Tim Streater
    Dec 18, 2013
Loading...

Share This Page