Results 1 to 7 of 7
  1. #1
    Join Date
    May 2008
    Location
    USA
    Posts
    114

    submit many forms in web page via one submit button

    Hi all,

    I have a table (1 column) where there is a form in each table data, all forms have the same name, I would submit forms via clicking on one button

    I created the following function for that button:

    Code:
    function submit_items()
    {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length;
    for(var i = 0; i < lastRow; i++)
    {
    document.forms[i].submit();
    }
    return true;
    }
    Where tblSample is the id for the table
    but that function submits the first and the last forms only?

    any other ideas for how to submit all forms via one click?

  2. #2
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    63
    You should use different IDs for each table. IDs within a page should be unique - that's what an ID is; a unique identifier.
    Why not use document.getElementsByTagName?

  3. #3
    Join Date
    Jul 2009
    Location
    Rethimno, Crete, Greece
    Posts
    7
    Your problem is the id. It's not correct having more than one id with the same name.

    An alternative solution is to put a custom attribute at the form and search for forms having the specific attribute (ex. myFormAttrib ="yes")

    An approach is the following:
    Instead of looping the tables you're looping the forms (getElementByTagName) and then you're checking for the correct attribute. Ex.
    if (formsArray[i].getAttribute('myFormAttrib') == 'yes') {
    formsArray[i].submit();
    }

    Sorry I didn't write you a complete source for the solution, but because of forum limitations (less than 5 messages) I cannot use the CODE tag

  4. #4
    Join Date
    Aug 2001
    Location
    Orange County, CA
    Posts
    532
    That would be really simple with jQuery; and it'd allow you to submit each form through Ajax so they don't redirect the browser on POST.

    You wouldn't even need to use IDs, you could just loop through every 'FORM' tag using their selectors (or FORMs at any depth).
    Jeff Standen, Chief of R&D, WebGroup Media LLC. - LinkedIn
    Cerb is a fast and flexible web-based platform for business collaboration and automation. http://www.cerbweb.com/

  5. #5
    Join Date
    Aug 2001
    Location
    Orange County, CA
    Posts
    532
    Also, if the interaction is consistent inside each cell (the same elements -- a textbox, a checkbox) you could just have a single FORM outside the table with a few <input type="hidden"> elements. You could have a single FORM span the table so you could draw cells. Changing an individual cell could copy its name and value (e.g. onBlur) into the hidden fields in the master FORM and submit in the background using Ajax. You'd catch the changes in the same place and just make the appropriate changes from what you're passed by that hidden form.

    You probably don't need 100 individual forms on each cell.
    Jeff Standen, Chief of R&D, WebGroup Media LLC. - LinkedIn
    Cerb is a fast and flexible web-based platform for business collaboration and automation. http://www.cerbweb.com/

  6. #6
    Join Date
    May 2008
    Location
    USA
    Posts
    114
    Thanks all for reply,

    I have a button to copy the table row that includs the form. Is there anyway to change the form id after copying row?

    code I used to copy row:
    Code:
    var tbl = document.getElementById('tblSample');
    var tbdy=tbl.getElementsByTagName('tr')[0].parentNode;
    var copied_cell=tbl.getElementsByTagName('tr')[0].cloneNode(true);
    tbdy.appendChild(copied_cell);
    the table at page load contains only one row and a button, and the fields should be in a form

  7. #7
    Join Date
    May 2008
    Location
    USA
    Posts
    114
    I think that may be we can change the form name after copying it, Is there a way to do that?

    so we will have each form with different id, so we can submit them via one click

    Thanks in advance

Similar Threads

  1. Submit button issue in IE
    By Johnny06man in forum Web Design and Content
    Replies: 6
    Last Post: 01-17-2005, 01:21 AM
  2. [Javascript] Submitting 4 forms with one submit button... Is it possible?
    By jonathanbull in forum Programming Discussion
    Replies: 15
    Last Post: 01-04-2005, 08:18 PM
  3. multiple submit forms on one page
    By InternetPEI in forum Web Design and Content
    Replies: 3
    Last Post: 06-12-2004, 11:48 PM
  4. Can you submit a form w/o a button?
    By Homeblock in forum Web Design and Content
    Replies: 5
    Last Post: 12-19-2003, 06:09 PM
  5. disable submit button
    By nvphone in forum Programming Discussion
    Replies: 2
    Last Post: 07-06-2003, 05:57 AM

Posting Permissions

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