I'm currently creating a booking form for users to be able to book places at an event. What i would like to do is create form fields via the select input for number of places. For example if the user selects 3 in the select field, then 3 name input fields will be created. The maximum amount of places is 12.
The only way I have managed to do this is using the following script, which shows the amount of fields selected by the user and adds a display none to all the others, this is a problem when validating the form as it is picking up the hidden fields too and wont let me submit the form. For example if the user selects 3, 3 inputs are shown but the remaining 9 are hidden.
<script type="text/javascript">
$(function () {
$(".limit").hide();
//set panels group
var panels = $(".limit", "#delegate_panels");
$('.delegate-number').change( function() {
//hide any previously shown panels
$(panels).hide();
//show the slice
$(panels).slice(0, parseInt($(this).val())).show();
});
});
</script>
Below is the code for the select field
<span>
<strong>Number of delegates</strong>
</span>
<select name="quantity" class="delegate-number">
<option>Please select...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
The code below is repeated 12 times and wrapped in #delegate_panels.
<li class="limit">
<div class="del-wrap">
<span>Title:</span>
<select name="item_options[title_1]" id="title1">
<option value="">--</option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Miss.">Miss.</option>
<option value="Dr.">Dr.</option>
</select>
</div>
<div class="name-wrap">
<span>Full Name:</span>
<input type="text" id="name1" name="name1" value="" size="30" />
</div>
</li>
Basically I would like it to do what the script above does, but to create the elements rather than displaying a slice and hiding the rest, which would then enable me to validate all the name fields and not have the hidden fields preventing the form submission.
Any thoughts would be much appreciated.