Jump to content

How to insert mulitple forms into db


runnerjp

Recommended Posts

Hey guys i have a script below where i can add other input boxes if needed.... these are then numberd plusing 1 to each one.

 

How can i make sure they are all added to my db?

 

An output might look liek this

 

Array ( [date] => 1 [am] => 1 [pm] => 1 [comment] => 1 [date2] => w [am2] => w [pm2] => w [comment2] => w [date3] => 1 [am3] => 1 [pm3] => 1 [comment3] => 1 [date4] => g [am4] => g [pm4] => g [comment4] => g )

 

 

<script>  
        function addRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          var row = tbl.insertRow(lastRow);  
            
          var cell1 = row.insertCell(0);  
          var input = document.createElement('input');  
          input.name = 'date' + lastRow;  
          input.id = 'date' + lastRow;  
          cell1.appendChild(input);  
            
          var cell2 = row.insertCell(1);  
          input = document.createElement('input');  
          input.name = 'am' + lastRow;  
          input.id = 'am' + lastRow;  
          cell2.appendChild(input);  
            
          var cell3 = row.insertCell(2);  
          input = document.createElement('input');  
          input.name = 'pm' + lastRow;  
          input.id = 'pm' + lastRow;  
          cell3.appendChild(input);  
            
          var cell4 = row.insertCell(3);  
          input = document.createElement('input');  
          input.name = 'comment' + lastRow;  
          input.id = 'comment' + lastRow;  
          cell4.appendChild(input);  
        }  
          
        function delRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          if (lastRow > 2) tbl.deleteRow(lastRow - 1);  
        }  
    </script>  

<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform"> 
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" id="thetable">  
   <tbody>  
     <tr>  
       <td>  
         <p align="center">Date</p></td>  
       <td>  
         <p align="center">Am</p></td>  
       <td>  
         <p align="center">Pm</p></td>  
       <td>  
         <p align="center">Comment</p></td>  
    </tr>  
     <tr>  
       <td>  
        <input name="date" /> </td>  
       <td>  
        <input name="am" /> </td>  
       <td>  
        <input name="pm" /></td>  
       <td>  
        <input name="comment" /></td>  
    </tr>  
  </tbody>  
</table>  
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse">  
     <tr>  
       <td>  
       <p align="center">  
          <input type="button" value="Add Row" onclick="addRow()" />  
          <input type="button" value="Subtract Row" onclick="delRow()" />  
                </p>  
       </td>  
    </tr>  
</table>

Link to comment
Share on other sites

I guess I'm sorta confused on what you want to do?  If just to simply make sure, then do tests to make sure it's working...

 

But sure that is not what you are asking, so if you want to make sure if dynamically they are added for a script then with some creativity, do calls to the tables behind the scenes to open up the table and read the fields you just entered and display error message if not there is nothing there. Could write a function for that.... but as I said little lost on what you are asking so maybe this helps.

Link to comment
Share on other sites

try to change your data array

<script>  
        function addRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          var row = tbl.insertRow(lastRow);  
            
          var cell1 = row.insertCell(0);  
          var input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][date]';  
          input.id = 'date' + lastRow;  
          cell1.appendChild(input);  
            
          var cell2 = row.insertCell(1);  
          input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][am]';  
          input.id = 'am' + lastRow;  
          cell2.appendChild(input);  
            
          var cell3 = row.insertCell(2);  
          input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][pm]';  
          input.id = 'pm' + lastRow;  
          cell3.appendChild(input);  
            
          var cell4 = row.insertCell(3);  
          input = document.createElement('input');  
          input.name = 'data[' + lastRow + '][comment]';  
          input.id = 'comment' + lastRow;  
          cell4.appendChild(input);  
        }  
          
        function delRow() {  
          var tbl = document.getElementById('thetable');  
          var lastRow = tbl.rows.length;  
          if (lastRow > 2) tbl.deleteRow(lastRow - 1);  
        }  
    </script>  

<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform"> 
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" id="thetable">  
   <tbody>  
     <tr>  
       <td>  
         <p align="center">Date</p></td>  
       <td>  
         <p align="center">Am</p></td>  
       <td>  
         <p align="center">Pm</p></td>  
       <td>  
         <p align="center">Comment</p></td>  
    </tr>  
     <tr>  
       <td>  
        <input name="data[1][date]" /> </td>  
       <td>  
        <input name="data[1][am]" /> </td>  
       <td>  
        <input name="data[1][pm]" /></td>  
       <td>  
        <input name="data[1][comment]" /></td>  
    </tr>  
  </tbody>  
</table>  
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse">  
     <tr>  
       <td>  
       <p align="center">  
          <input type="button" value="Add Row" onclick="addRow()" />  
          <input type="button" value="Subtract Row" onclick="delRow()" />
                </p>  
       </td>  
    </tr>  
</table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.