Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default Dynamic table rows

    I'm creating a form online laid on in a table. It is a order form for images
    from a educational library. We recieve orders from 1-thousands of images. So,
    I created a form online that is submitted to us automatically. But, as of now,
    it has room for 10 images in an order. Can I use something, my guess would be
    JavaScript and put in an arguement that woudl repeat the clean row of the order
    form when you told it you have another image or when you fill in information
    for the current one.

    So, it would start as a form for 1 image. When you filledin the page number
    the image is on, author, etc. it would automatically create anotehr row for a
    second image with the same blank fields (page, author, etc.).

    Any pointers? Any tutorials or starter scripts? Anything to watch out for?

    Thanks
    Dan J.


    Dan Joyce Guest

  2. Similar Questions and Discussions

    1. #25473 [Opn->Bgs]: Updating single row in table causing all rows in table to be updated.
      ID: 25473 Updated by: sniper@php.net Reported By: jim at bluedojo dot com -Status: Open +Status: ...
    2. #25473 [Fbk->Opn]: Updating single row in table causing all rows in table to be updated.
      ID: 25473 User updated by: jim at bluedojo dot com Reported By: jim at bluedojo dot com -Status: Feedback +Status: ...
    3. #25473 [Opn->Fbk]: Updating single row in table causing all rows in table to be updated.
      ID: 25473 Updated by: sniper@php.net Reported By: jim at bluedojo dot com -Status: Open +Status: ...
    4. #25473 [Opn]: Updating single row in table causing all rows in table to be updated.
      ID: 25473 User updated by: jim at bluedojo dot com Reported By: jim at bluedojo dot com Status: Open Bug Type: ...
    5. #25473 [NEW]: Updating single row in table causing all rows in table to be updated.
      From: jim at bluedojo dot com Operating system: WinXP PHP version: 4.3.3 PHP Bug Type: MySQL related Bug description: ...
  3. #2

    Default Re: Dynamic table rows

    Check out the link, I think it's what you want

    Ken

    [url]http://javascript.internet.com/miscellaneous/add-a-row.html[/url]
    The ScareCrow Guest

  4. #3

    Default Re: Dynamic table rows

    That is what I'm looking for in a way. But, it doesn't seem to be editable in
    the way I need, at least at first glance. The problem is likely my limited
    JavaScript knowledge. For instance, I was trying to use document.write to
    write the different html things like TR, TD, etc. I don't know what this all
    is and how to edit it.

    function addRow(id){
    var tbody = document.getElementById
    (id).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode("column 1"))
    var td2 = document.createElement("TD")
    td2.appendChild (document.createTextNode("column 2"))
    row.appendChild(td1);
    row.appendChild(td2);
    tbody.appendChild(row);

    Obviously, appendChild, document.createElement, and the like are JavaScript
    commands that I do not know. But, they seemto only be able to create TD, etc,
    not input areas (Textfields and the like). Is that true? Has JavaScript
    really changed that much since I used it 4 years ago or did I just never use
    such commands?

    Thansk
    Dan J.

    Dan Joyce Guest

  5. #4

    Default Re: Dynamic table rows

    I have attached a complete page, just copy and paste. See if this is what you
    are after.

    Ken


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    function addRow(id){
    var elementCount =
    parseInt(document.getElementById('numberOfUploads' ).value) + 1;
    var tbody = document.getElementById(id).getElementsByTagName(" TBODY")[0];
    var row = document.createElement("TR");
    var td1 = document.createElement("TD");
    td1.appendChild(document.createTextNode("Upload Document " +
    elementCount));
    var td2 = document.createElement("TD");
    td2.appendChild (document.createElement("<input type='file'
    name='upload"+elementCount+"'>"));
    row.appendChild(td1);
    row.appendChild(td2);
    tbody.appendChild(row);
    document.getElementById('numberOfUploads').value = elementCount;
    }
    // End -->
    </script>
    </head>

    <body>

    <a href="javascript:addRow('myTable')">Add row</a>
    <form>
    <input type="hidden" name="numberOfUploads" value="1">
    <table id="myTable" cellspacing="0" border="1">
    <tbody>
    <tr>
    <td>Upload Document 1</td><td><input type="file" name="upload1"></td>
    </tr>
    </tbody>
    </table>
    </form>


    </body>
    </html>

    The ScareCrow Guest

  6. #5

    Default Re: Dynamic table rows

    Thanks, but that doesn't work in FireFox. I need something that will work in every newer browser. Any idea why it wouldn't work?

    Thanks
    Dan J.
    Dan Joyce Guest

  7. #6

    Default Re: Dynamic table rows

    Where I work, I only need to be concerned with IE and NN. So I can't help with
    firefox.

    From the error message I would say that it does not like the code
    document.getElementById
    So you will need to research firefox and see what code is the same.
    The createElement function will create any element that you need.

    Ken

    The ScareCrow Guest

  8. #7

    Default Re: Dynamic table rows

    FF does support document.getElementById as far as I know, but you can always
    use MM findObj() function instead.


    The ScareCrow wrote:
    > Where I work, I only need to be concerned with IE and NN. So I can't
    > help with firefox.
    >
    > From the error message I would say that it does not like the code
    > document.getElementById
    > So you will need to research firefox and see what code is the same.
    > The createElement function will create any element that you need.
    >
    > Ken

    rob::digitalburn Guest

  9. #8

    Default Re: Dynamic table rows

    Sorry, learning this stuff as I go. Never had to do ANY of this 4 years ago.
    I dont' nkow what I mean by

    "use MM findObj() function instead."

    How do I go about this? It does seem to be the problem. Here is my updated
    code that is much cleaner AND WORKS! in IE (ugh)

    Thanks
    Dan J.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    function addRow(id){
    var imageCount = parseInt(document.getElementById('numberOfImages') .value)
    + 1;
    var tbody = document.getElementById(id).getElementsByTagName(" TBODY")[0];
    var row = document.createElement("TR");
    var td1 = document.createElement("TD");
    td1.setAttribute("align","center");
    td1.appendChild(document.createTextNode(imageCount ));
    var td2 = document.createElement("TD");
    td2.setAttribute("align","center");
    td2.appendChild (document.createElement("<input type='textfield'
    name='PgPlFig"+imageCount+"' size='10' maxlength='20'>"));
    var td3 = document.createElement("TD");
    td3.setAttribute("align","center");
    td3.appendChild (document.createElement("<input type='textfield'
    name='ArchArtFirm"+imageCount+"' size='15' maxlength='50'>"));
    var td4 = document.createElement("TD");
    td4.setAttribute("align","center");
    td4.appendChild (document.createElement("<input type='textfield'
    name='Description"+imageCount+"' size='45' maxlength='100'>"));
    var td5 = document.createElement("TD");
    td5.setAttribute("align","center");
    td5.appendChild (document.createElement("<input type='textfield'
    name='ImageDate"+imageCount+"' size='10' maxlength='10'>"));
    var td6 = document.createElement("TD");
    td6.setAttribute("align","center");
    td6.appendChild (document.createElement("<input type='checkbox'
    name='Slide"+imageCount+"' value='YES'>"));
    td6.appendChild (document.createTextNode("S"));
    td6.appendChild (document.createElement("<input type='checkbox'
    name='Digital"+imageCount+"' value='YES'>"));
    td6.appendChild (document.createTextNode("D"));
    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);
    row.appendChild(td5);
    row.appendChild(td6);
    tbody.appendChild(row);
    document.getElementById('numberOfImages').value = imageCount;
    }
    // End -->
    </script>
    </head>

    <body>


    <form>
    <input type="hidden" name="numberOfImages" id="numberOfImages" value="1">
    <table id="orderTable" cellspacing="0" border="1">
    <thead>
    <tr>
    <td width="13">&nbsp;</td>
    <td width="71"><div
    align="center"><strong>pg/pl/fig</strong></div></td>
    <td width="202"><div align="center"><strong>Architect, Aritst or Firm
    </strong></div></td>
    <td width="342"><div align="center"><strong>Project Title / Building
    Name / Description / Location </strong></div></td>
    <td width="162"><div align="center"><strong>Date</strong></div></td>
    <td width="96"><div align="center"><strong>Slide or Digital Image
    </strong></div></td>
    </tr>
    </thead>

    <tbody>
    <tr>
    <td><div align="center">1</div></td>
    <td><div align="center"><input name="1PgPlFig" type="text" id="1PgPlFig"
    size="10" maxlength="20"></div></td>
    <td><div align="center"><input name="1ArchArtFirm" type="text"
    id="1ArchArtFirm" size="15" maxlength="50"></div></td>
    <td><div align="center"><input name="1Description" type="text"
    id="1Description" size="45" maxlength="100"></div></td><br>
    <td><div align="center"><strong><input name="1ImageDate" type="text"
    id="1ImageDate" size="10" maxlength="10"></strong></div></td>
    <td><div align="center">
    <label><input type="checkbox" name="1Slide" value="YES">S</label>
    <label><input type="checkbox" name="1Digital" value="YES">D</label>
    </div></td>

    </tr>
    </tbody>
    </table>
    </form>
    <a href="javascript:addRow('orderTable')">Add row</a>

    </body>
    </html>


    Dan Joyce Guest

  10. #9

    Default Re: Dynamic table rows

    I've been doing this stuff for longer than four years, so it's always been
    around :)

    What I mean is, just change every instance of document.getElementById() to
    findObj(), then make sure that the findObj function is somewhere in your JS
    code. It's available in the code snippets library in DW.

    It looks as if you're going about what you're doing in a very labourious
    manner, although I haveb't been following this thread, so I'm not exactly
    sure what you're trying to do.


    Dan Joyce wrote:
    > Sorry, learning this stuff as I go. Never had to do ANY of this 4
    > years ago. I dont' nkow what I mean by
    >
    > "use MM findObj() function instead."
    >
    > How do I go about this? It does seem to be the problem. Here is my
    > updated code that is much cleaner AND WORKS! in IE (ugh)
    >
    > Thanks
    > Dan J.
    >
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    >
    > <html>
    > <head>
    > <title>Untitled</title>
    > <SCRIPT LANGUAGE="JavaScript">
    >
    > <!-- Begin
    > function addRow(id){
    > var imageCount =
    > parseInt(document.getElementById('numberOfImages') .value) + 1;
    > var tbody =
    > document.getElementById(id).getElementsByTagName(" TBODY")[0];
    > var row = document.createElement("TR"); var td1 =
    > document.createElement("TD"); td1.setAttribute("align","center");
    > td1.appendChild(document.createTextNode(imageCount ));
    > var td2 = document.createElement("TD");
    > td2.setAttribute("align","center");
    > td2.appendChild (document.createElement("<input type='textfield'
    > name='PgPlFig"+imageCount+"' size='10' maxlength='20'>"));
    > var td3 = document.createElement("TD");
    > td3.setAttribute("align","center");
    > td3.appendChild (document.createElement("<input type='textfield'
    > name='ArchArtFirm"+imageCount+"' size='15' maxlength='50'>"));
    > var td4 = document.createElement("TD");
    > td4.setAttribute("align","center");
    > td4.appendChild (document.createElement("<input type='textfield'
    > name='Description"+imageCount+"' size='45' maxlength='100'>"));
    > var td5 = document.createElement("TD");
    > td5.setAttribute("align","center");
    > td5.appendChild (document.createElement("<input type='textfield'
    > name='ImageDate"+imageCount+"' size='10' maxlength='10'>"));
    > var td6 = document.createElement("TD");
    > td6.setAttribute("align","center");
    > td6.appendChild (document.createElement("<input type='checkbox'
    > name='Slide"+imageCount+"' value='YES'>"));
    > td6.appendChild (document.createTextNode("S"));
    > td6.appendChild (document.createElement("<input type='checkbox'
    > name='Digital"+imageCount+"' value='YES'>"));
    > td6.appendChild (document.createTextNode("D"));
    > row.appendChild(td1);
    > row.appendChild(td2);
    > row.appendChild(td3);
    > row.appendChild(td4);
    > row.appendChild(td5);
    > row.appendChild(td6);
    > tbody.appendChild(row);
    > document.getElementById('numberOfImages').value = imageCount;
    > }
    > // End -->
    > </script>
    > </head>
    >
    > <body>
    >
    >
    > <form>
    > <input type="hidden" name="numberOfImages" id="numberOfImages"
    > value="1"> <table id="orderTable" cellspacing="0" border="1">
    > <thead>
    > <tr>
    > <td width="13">&nbsp;</td>
    > <td width="71"><div
    > align="center"><strong>pg/pl/fig</strong></div></td>
    > <td width="202"><div align="center"><strong>Architect,
    > Aritst or Firm </strong></div></td>
    > <td width="342"><div align="center"><strong>Project Title /
    > Building Name / Description / Location </strong></div></td>
    > <td width="162"><div
    > align="center"><strong>Date</strong></div></td> <td
    > width="96"><div align="center"><strong>Slide or Digital Image
    > </strong></div></td> </tr>
    > </thead>
    >
    > <tbody>
    > <tr>
    > <td><div align="center">1</div></td>
    > <td><div align="center"><input name="1PgPlFig" type="text"
    > id="1PgPlFig" size="10" maxlength="20"></div></td>
    > <td><div align="center"><input name="1ArchArtFirm" type="text"
    > id="1ArchArtFirm" size="15" maxlength="50"></div></td>
    > <td><div align="center"><input name="1Description" type="text"
    > id="1Description" size="45" maxlength="100"></div></td><br>
    > <td><div align="center"><strong><input name="1ImageDate"
    > type="text" id="1ImageDate" size="10"
    > maxlength="10"></strong></div></td> <td><div align="center">
    > <label><input type="checkbox" name="1Slide" value="YES">S</label>
    > <label><input type="checkbox" name="1Digital" value="YES">D</label>
    > </div></td>
    >
    > </tr>
    > </tbody>
    > </table>
    > </form>
    > <a href="javascript:addRow('orderTable')">Add row</a>
    >
    > </body>
    > </html>

    rob::digitalburn Guest

  11. #10

    Default Re: Dynamic table rows

    First, there is no element of type "textfield"

    Then the main problem is the following line
    td2.appendChild (document.createElement("<input type='textfield'
    name='PgPlFig"+imageCount+"' size='10' maxlength='20'>"));

    While this works in IE and NN, firefox does not like it, so you need to do it
    by the standard (W3C), like so

    var td2 = document.createElement("TD");
    td2.setAttribute("align","center");

    var td2a = document.createElement("input");
    td2a.type = 'text';
    td2a.id = 'PgPlFig' + imageCount ;
    td2a.name = 'PgPlFig' + imageCount;
    td2a.size = '10';
    td2a.maxlength = '20';
    td2.appendChild (td2a);

    Ken


    The ScareCrow Guest

  12. #11

    Default Re: Dynamic table rows

    Hum, I just read your original question, I think you can do it an aweful lot
    more simply than you are doing. I wouldn't use tables for a start.


    rob::digitalburn Guest

  13. #12

    Default Re: Dynamic table rows

    Great, but then how would you do it?

    Thanks everyone for the help. I'm going to try a previous post that gave me
    the exact script I need. I'll replace all those text fields like that.
    Thanks! I'll get back with how it is. . .

    Dan Joyce Guest

  14. #13

    Default Re: Dynamic table rows

    So, I put this all to the suggestion posted by ScareCrow (or I thought I did):

    <!-- Begin
    function addRow(id){
    var imageCount = parseInt(document.getElementById('numberOfImages') .value)
    + 1;
    var tbody = document.getElementById(id).getElementsByTagName(" TBODY")[0];
    var row = document.createElement("TR");

    var td1 = document.createElement("TD");
    td1.appendChild (document.createElement("<input type='hidden'
    name='"+imageCount+"' value='&nbsp;'>"));
    td1.setAttribute("align","center");
    td1.appendChild(document.createTextNode(imageCount ));

    var td1 = document.createElement("TD");
    td1.setAttribute("align","center");

    var td1a = document.createElement("input");
    td1a.type = 'hidden';
    td1a.id = imageCount;
    td1a.name = imageCount;
    td1a.value = "&nbsp;" ;
    td1.appendChild (td1a);



    var td2 = document.createElement("TD");
    td2.setAttribute("align","center");

    var td2a = document.createElement("input");
    td2a.type = 'text';
    td2a.id = 'PgPlFig' + imageCount ;
    td2a.name = 'PgPlFig' + imageCount;
    td2a.size = '10';
    td2a.maxlength = '20';
    td2.appendChild (td2a);

    var td3 = document.createElement("TD");
    td2.setAttribute("align","center");

    var td3a = document.createElement("input");
    td3a.type = 'text';
    td3a.id = 'ArchArtFirm' + imageCount ;
    td3a.name = 'ArchArtFirm' + imageCount;
    td3a.size = '15';
    td3a.maxlength = '50';
    td3.appendChild (td3a);


    var td4 = document.createElement("TD");
    td2.setAttribute("align","center");

    var td4a = document.createElement("input");
    td4a.type = 'text';
    td4a.id = 'Description' + imageCount ;
    td4a.name = 'Description' + imageCount;
    td4a.size = '45';
    td4a.maxlength = '100';
    td4.appendChild (td4a);


    var td5 = document.createElement("TD");
    td2.setAttribute("align","center");

    var td5a = document.createElement("input");
    td5a.type = 'text';
    td5a.id = 'ImageDate' + imageCount ;
    td5a.name = 'ImageDate' + imageCount;
    td5a.size = '10';
    td5a.maxlength = '10';
    td5.appendChild (td5a);


    var td6 = document.createElement("TD");
    td6.setAttribute("align","center");

    var td6a = document.createElement("input");
    td6a.type = 'checkbox';
    td6a.id = 'Slide' + imageCount;
    td6a.name = 'Slide' + imageCount;
    td6a.value = 'YES';
    td6a.appendChild (td5a);
    var td6b = document.createElement("input");
    td6b.type = 'checkbox';
    td6b.id = 'Slide' + imageCount;
    td6b.name = 'Slide' + imageCount;
    td6b.value = 'YES';
    td6b.appendChild (td5b);


    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);
    row.appendChild(td5);
    row.appendChild(td6);
    tbody.appendChild(row);
    document.getElementById('numberOfImages').value = imageCount;
    }
    // End -->

    still no luck in Safari or FireFox. Did I screw it up?

    Dan Joyce Guest

  15. #14

    Default Re: Dynamic table rows

    You have made a few mistakes.

    You have td1 defined twice
    You have also assigned the incorrect values for the checkboxes.

    I have attached a working copy.

    Ken

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    <script language="JavaScript">
    <!-- Begin
    function addRow(id){
    var imageCount = parseInt(document.getElementById('numberOfImages') .value) + 1;
    var tbody = document.getElementById(id).getElementsByTagName(" TBODY")[0];
    var row = document.createElement("TR");

    var td1 = document.createElement("TD");
    var td1a = document.createElement("DIV");
    td1a.align = 'center';
    td1a.appendChild(document.createTextNode(imageCoun t));
    td1.appendChild(td1a);


    var td2 = document.createElement("TD");
    var td2a = document.createElement("DIV");
    td2a.align = 'center';
    var td2b = document.createElement("input");
    td2b.type = 'text';
    td2b.id = 'PgPlFig' + imageCount ;
    td2b.name = 'PgPlFig' + imageCount;
    td2b.size = '10';
    td2b.maxlength = '20';
    td2a.appendChild (td2b);
    td2.appendChild (td2a);

    var td3 = document.createElement("TD");
    var td3a = document.createElement("DIV");
    td3a.align = 'center';
    var td3b = document.createElement("input");
    td3b.type = 'text';
    td3b.id = 'ArchArtFirm' + imageCount ;
    td3b.name = 'ArchArtFirm' + imageCount;
    td3b.size = '15';
    td3b.maxlength = '50';
    td3a.appendChild (td3b);
    td3.appendChild (td3a);


    var td4 = document.createElement("TD");
    var td4a = document.createElement("DIV");
    td4a.align = 'center';
    var td4b = document.createElement("input");
    td4b.type = 'text';
    td4b.id = 'Description' + imageCount ;
    td4b.name = 'Description' + imageCount;
    td4b.size = '45';
    td4b.maxlength = '100';
    td4a.appendChild (td4b);
    td4.appendChild (td4a);


    var td5 = document.createElement("TD");
    var td5a = document.createElement("DIV");
    td5a.align = 'center';
    var td5b = document.createElement("input");
    td5b.type = 'text';
    td5b.id = 'ImageDate' + imageCount ;
    td5b.name = 'ImageDate' + imageCount;
    td5b.size = '10';
    td5b.maxlength = '10';
    td5a.appendChild (td5b);
    td5.appendChild (td5a);


    var td6 = document.createElement("TD");
    var td6a = document.createElement("DIV");
    td6a.align = 'center';

    var td6b = document.createElement("input");
    td6b.type = 'checkbox';
    td6b.id = 'Slide' + imageCount;
    td6b.name = 'Slide' + imageCount;
    td6b.value = 'YES';
    td6a.appendChild (td6b);
    td6a.appendChild(document.createTextNode("S "));
    td6.appendChild (td6a);

    var td6c = document.createElement("input");
    td6c.type = 'checkbox';
    td6c.id = 'Slide' + imageCount;
    td6c.name = 'Slide' + imageCount;
    td6c.value = 'YES';
    td6a.appendChild (td6c);
    td6a.appendChild(document.createTextNode("D"));

    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);
    row.appendChild(td5);
    row.appendChild(td6);
    tbody.appendChild(row);
    document.getElementById('numberOfImages').value = imageCount;
    }
    // End -->
    </script>
    </head>

    <body>

    <form>
    <input type="hidden" name="numberOfImages" id="numberOfImages" value="1">
    <table id="orderTable" cellspacing="0" border="1">
    <thead>
    <tr>
    <td width="13">&nbsp;</td>
    <td width="71"><div align="center"><strong>pg/pl/fig</strong></div></td>
    <td width="202"><div align="center"><strong>Architect, Aritst or Firm
    </strong></div></td>
    <td width="342"><div align="center"><strong>Project Title / Building Name /
    Description / Location </strong></div></td>
    <td width="162"><div align="center"><strong>Date</strong></div></td>
    <td width="96"><div align="center"><strong>Slide or Digital Image
    </strong></div></td>
    </tr>
    </thead>

    <tbody>
    <tr>
    <td><div align="center">1</div></td>
    <td><div align="center"><input name="1PgPlFig" type="text" id="1PgPlFig"
    size="10" maxlength="20"></div></td>
    <td><div align="center"><input name="1ArchArtFirm" type="text"
    id="1ArchArtFirm" size="15" maxlength="50"></div></td>
    <td><div align="center"><input name="1Description" type="text"
    id="1Description" size="45" maxlength="100"></div></td><br>
    <td><div align="center"><strong><input name="1ImageDate" type="text"
    id="1ImageDate" size="10" maxlength="10"></strong></div></td>
    <td><div align="center">
    <input type="checkbox" name="1Slide" value="YES">S
    <input type="checkbox" name="1Digital" value="YES">D
    </div></td>

    </tr>
    </tbody>
    </table>
    </form>
    <a href="javascript:addRow('orderTable')">Add row</a>


    </body>
    </html>

    The ScareCrow Guest

  16. #15

    Default Re: Dynamic table rows

    Scarecrow, you're my hero. Now it works in all three browsers. I just have to
    plug in the rest of the page that already works and put in the script to
    submit. I can do all of that. THANKS!!!!!!

    Dan J.

    Dan Joyce Guest

  17. #16

    Default Re: Dynamic table rows

    Thanks to everyone whop responded to this query. I came across it while looking
    for an answer to a similar question I've been assigned..

    If I wanted to add two rows at a time (e.g., instead of having six columns in
    the example, there were two rows of three columns) , what changes to the
    javascript code would be required? Obviously, I'm a newcomer to javascript, and
    any help would be greatly appreciated.

    john_crowley Guest

  18. #17

    Default Re: Dynamic table rows

    Sorry Dan, I did not get an email to let me know a post had been made.

    If you need to start from zero, just set the form field to zero

    <input type="hidden" name="numberOfImages" id="numberOfImages" value="0">


    John,
    So, I assume you want to add 2 rows of 3 columns each time ??

    Then

    This adds the row, so for each row just give the var a different name
    var row = document.createElement("TR");

    The columns are then added to the row by
    row.appendChild(td1);


    So to do what you want to do, all you need to do is add the row right after
    the first row
    var row1 = document.createElement("TR");

    Then change the following
    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);
    row.appendChild(td5);
    row.appendChild(td6);

    To
    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row1.appendChild(td4);
    row1.appendChild(td5);
    row1.appendChild(td6);
    tbody.appendChild(row);
    tbody.appendChild(row1);

    Ken




    The ScareCrow Guest

  19. #18

    Default Re: Dynamic table rows

    Thanks for the response, but I have that solution in there already. The image counter should be resetting. Any idea why it doesn't?

    Thanks
    Dan j.
    Dan Joyce Guest

  20. #19

    Default Re: Dynamic table rows

    Dan,
    The following line should reset the variable (to the value in the hidden form
    field) each time the function is executed
    var imageCount = parseInt(document.getElementById('numberOfImages') .value) + 1;

    When the page is loaded this form field should have the default value (1, 0,
    ect..)

    So, I'm not sure why it is not. But you could try the following:
    Declare the variable outside the function, like so

    var imageCount = 0;
    Then change the following line
    var imageCount = parseInt(document.getElementById('numberOfImages') .value) + 1;

    To
    imageCount = parseInt(document.getElementById('numberOfImages') .value) + 1;

    It also might be an idea to change the hidden form field to text, so you can
    see it in the page. Then reload the page to ensure that the correct value is
    being loaded.

    Ken


    The ScareCrow Guest

  21. #20

    Default Re: Dynamic table rows

    Thanks Ken -

    It's working well, but I do have one last question. If I wanted to have a
    field name in the first column (.e.g, "Name"), and then have it update each
    time a new row is added (e.g., "Name2", "Name3", etc.), how would I go about it?

    Again, thanks for the help on this.

    john_crowley Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139