Addressing form fields in a loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Banks

    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(ArrayT oUse){
    for (i=0; i < ArrayToUse.leng th; i++){
    //alert(ArrayToUs e[i]);
    //alert("I is " + i + " Thurs array is " + ThursArray);
    document.add_re cord_form.date + i + .value = ArrayToUse[i];
    }
    }


  • Lasse Reichstein Nielsen

    #2
    Re: Addressing form fields in a loop

    "Andrew Banks" <banksy@nospamb lueyonder.co.uk > writes:
    [color=blue]
    > 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?[/color]

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

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Dr John Stockton

      #3
      Re: Addressing form fields in a loop

      JRS: In article <XALub.4818$WX7 .41808000@news-text.cableinet. net>, seen
      in news:comp.lang. javascript, Andrew Banks <banksy@nospamb lueyonder.co.u
      k> posted at Wed, 19 Nov 2003 15:01:11 :-
      [color=blue]
      >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");[/color]

      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.get Date()+7) ) document.writel n(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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

      Comment

      Working...