View Full Version : add more field

27 Apr 2011, 09:25 AM
i would like a form that has one repetative field. if the user would like to enter more of the fields (ex. files) , they click on a button to show more fields.

27 Apr 2011, 01:56 PM
Try test and use this example.
The user can add text-fields, but you can replace it with type="file"

<script type="text/javascript">
// - www.coursesweb.net/javascript/
// creates an input element and adds it before the Submit button
function add_input() {
var new_input = document.createElement("input");
new_input.setAttribute("type", "text");
new_input.setAttribute("name", "nume[]");
new_input.style.display = 'block'; // Seteaza display:block; pt. a afisa casutele unele sub altele

// sets the objects for reference (reper) and parent
var reper = document.getElementById('submit');
var parinte = reper.parentNode;

// Adds the new element
parinte.insertBefore(new_input, reper);

<form action="">
<input type="text" name="nume[]" />
<input type="submit" value="Submit" id="submit" /><br /><br />
<input type="button" value="Add field" onclick="add_input()" />