0

I have the following jQuery code:

$('#btnAdd').click(function() {
var i = ($('#stuff >tbody >tr').length)+1;
$('#stuff >tbody >tr:last').clone(true).find("input,select").each(function(){
$(this).attr({
'name': function(_, name){
   return name + i;
},
'value': ''
});}).end().insertAfter('#stuff >tbody>tr:last').show();

Which produces the following DOM:

<tr>
<td class="td_6">
<select name="name1">
<option selected="" value="Bricklayers">Bricklayers</option>
<option value="Sheet Metal Workers">Sheet Metal Workers</option>
<option value="Sprinkler Fitters">Sprinkler Fitters</option>
</select>
<td>
<td class="td_6">
<input name="V_union" value="1" type="radio">Yes<input name="V_union" value="0" type="radio" checked="checked">No
</td>
<td class="td_6">
<input name="V_picketed" value="1" type="radio">Yes<input name="V_picketed" value="0" type="radio" checked="checked">No
</td>
<td>
</td>
</tr>

<tr style="">
<td class="td_6">
<select name="name13" value="">
<option selected="" value="Bricklayers">Bricklayers</option>
<option value="Sheet Metal Workers">Sheet Metal Workers</option>
<option value="Sprinkler Fitters">Sprinkler Fitters</option>
</select>
</td>
<td class="td_6">
<input name="V_union3" value="" type="radio">Yes<input name="V_union3" value="" type="radio" checked="checked">No
</td>
<td class="td_6">
<input name="V_picketed3" value="" type="radio">Yes<input name="V_picketed3" value="" type="radio" checked="checked">No
</td>
<td>
</td>
</tr>

Here is the form tag:

<form method="post" action="view_job.php" name="updateViolations" enctype="multipart/form-data">

The dynamically entered rows are within the tags.

When I do a var_dump on $_POST, I am not seeing the new dynamically generated form inputs in the $_POST variable.

I have checked several other questions, and it appears that I am doing everything right, but I'm lost.

3
  • Are you just submitting the form normally? Where is the form element? Jan 14, 2013 at 18:56
  • Can you post the whole form that results from the dynamically generated form inputs? Jan 14, 2013 at 18:57
  • @ExplosionPills The form is submitted normally. Jan 14, 2013 at 19:01

2 Answers 2

2

Thanks to all that submitted. Turned out it was an easy fix.

https://stackoverflow.com/a/3687359/983061

Thanks again.

1
  • Similar issue, same problem. Thanks!
    – JonDoeCA
    Jan 27, 2013 at 22:03
1

It looks like there are a few duplicate id attributes. An id can only be used once per page.

You might consider changing those from id to class (classes can be used multiple times per page).

Duplicates: clonedInput, td_6_left, check1, check13

2
  • would that mess up the form submitting? Jan 14, 2013 at 19:08
  • I just removed all the duplicate ID's that were on the page, and I'm still not seeing the variables in the $_POST Jan 14, 2013 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.