document.form and array?

Discussion in 'Javascript' started by Flyzone, Aug 28, 2007.

  1. Flyzone

    Flyzone Guest

    Hi, i have a little trouble with javascript putting data in a form
    html.
    I'm parsing an xml file with DomXML (into an hta file), in a loop:

    if (i==0) {
    document.form.moduleA_0.value = varnameA;
    document.form.moduleB_0.value = varnameB;
    ...
    else if (i==1) {
    document.form.moduleA_1.value = varnameA;
    document.form.moduleB_1.value = varnameB;
    ...
    else if (i==2) {
    document.form.moduleA_2.value = varnameA;
    document.form.moduleB_2.value = varnameB;
    ...
    And in the html form, many input field idetify by the name moduleA,
    moduleB.....
    That is very boring.
    There is a way to identify them in javascript as 'moduleA_'+i like an
    array,
    or to write as array? I tried to make a moduleA = new array(10), but i
    get many
    errors in thml.
    Could someone give me some tips? Reading in the old posts didn't help
    me (wrong key search?).
    Thanks in advance
    Flyzone, Aug 28, 2007
    #1
    1. Advertising

  2. Flyzone

    RobG Guest

    On Aug 28, 5:21 pm, Flyzone <> wrote:
    > Hi, i have a little trouble with javascript putting data in a form
    > html.
    > I'm parsing an xml file with DomXML (into an hta file), in a loop:
    >
    > if (i==0) {
    > document.form.moduleA_0.value = varnameA;
    > document.form.moduleB_0.value = varnameB;
    > ...
    > else if (i==1) {
    > document.form.moduleA_1.value = varnameA;
    > document.form.moduleB_1.value = varnameB;
    > ...
    > else if (i==2) {
    > document.form.moduleA_2.value = varnameA;
    > document.form.moduleB_2.value = varnameB;
    > ...
    > And in the html form, many input field idetify by the name moduleA,
    > moduleB.....
    > That is very boring.
    > There is a way to identify them in javascript as 'moduleA_'+i like an
    > array,


    Yes (though what you are dealing with is not an array even though you
    can access it by index):

    var form = document.form;
    form['moduleA_' + i] = varnameA;
    form['moduleB_' + i] = varnameB;


    see :

    <URL: http://www.jibbering.com/faq/#FAQ4_39 >


    --
    Rob
    RobG, Aug 28, 2007
    #2
    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. NotGiven
    Replies:
    3
    Views:
    322
    Michael D. Kersey
    May 13, 2004
  2. Edward
    Replies:
    1
    Views:
    128
    Lasse Reichstein Nielsen
    Jan 4, 2004
  3. Edward
    Replies:
    0
    Views:
    167
    Edward
    Feb 5, 2004
  4. Edward
    Replies:
    1
    Views:
    108
    Richard Cornford
    Apr 15, 2004
  5. NotGiven
    Replies:
    3
    Views:
    284
    Michael D. Kersey
    May 13, 2004
Loading...

Share This Page