.append array fields
.append array fields
I am using jquery append() to clone a div consisting textfield and checkbox both as separate arrays. Obviously, when posted checkbox will only show if checked.
Is it possible to link the checkbox and textfield with a common key and the key also increment with appended div?
or
is it possible to change the field name every time it's appended?
Hope I am clear in explaining. Below is the code.
- <script type="text/javascript">
- $(document).ready(function() {
- $("#addTestAppend").click(function() {
- $("#testAppend").append(
- "<div>"
- +"<input type=\"text\" name=\"name[]\" /><br />"
- +"<input type=\"checkbox\" name=\"needDivTwo[]\" class=\"needDivTwo\" />"
- +"</div>"
- );
- });
- });
- </script>
- <form name="name" method="post" action="formProcess.php">
- <div id=testAppend>
- <div>
- <input type="text" name="name[]" /><br />
- <input type="checkbox" name="needDivTwo[]" class="needDivTwo" />
- </div>
- </div>
- <input type="button" id="addTestAppend" value="[ Add Append ]" />
- </form>