Forum Moderators: coopster
I apologize if this question has been answered before but after searching for a little, I haven't found anything that is quite what I'm looking for.
I am building a web-based version of a paper form that we are currently using at my work and one of the requirements of this project is that the web form look exactly like the paper version.
On this form is a section that almost looks like a spreadsheet. It has 4 columns and there are 5 rows. All of these rows may not actually be used so to make my form a little cleaner, I would like to be able to dynamically add rows to this web form so we can have more or less than 5 rows if necessary. Adding the rows dynamically to the page is not my problem. I currently have this working with javascript. The problem is how do I store these dynamically created rows in MySQL? I know I need to use an array and store the form variables in an array but how do I process this in my form processor? I would like each row of this form to be a new row in my database table.
The code I have currently is below. I don't have any processing code for this form yet as I'm not sure how to go about it. I imagine I need a foreach loop? I modified the code below from an example I found in another forum. If the original author see this, thank you for the script! :)
<script type="text/javascript">
var clone;
function cloneDiv(){
var divs=document.getElementById('myDiv').getElementsByTagName('div');
clone=divs[divs.length-1].cloneNode(true);
}
function addDiv(){
var root=document.getElementById('myDiv');
var divs=root.getElementsByTagName('div');
root.appendChild(clone);
clone=divs[divs.length-1].cloneNode(true);
}
onload=cloneDiv
</script>
</head>
<body>
<form id="form" action="manage.php?action=save" method="post">
<div id="myDiv">
<div>
<input type="text" name="Date[]"><input type="text" name="Qty[]"><input type="text" name="Description[]"><input
</div>
</div>
<input name="button" type="button" value="Add Row" onclick="addDiv()">
<input name="submit" type="submit" value="Submit">
</form>
Thanks for the reply. That code is exactly what I wanted. I'm glad I had the right idea. The index is what I was confused about. Now, once this is submitted to the database, what is the best way to pull the information back into the fields for editing?
PS: From your username I would imagine you're a photographer? If so, you may be interested to know I work for a TV station and this project is for tape logging...