I have my code in PHP, and I'm using a select box, built in one array. What I pretend is to clone the select with jQuery for add how many rows I want.
Example:
<a href="javascript:void(0);" id='add_line_class'>Adicionar classe</a><a class='icon add_btn_icon activated_icon'></a>
<a href="javascript:void(0);" id='rem_line_class'>Remover classe</a><a class='icon cross_btn_icon'></a>
<table id="tbl_add_class" border="0" width="100%">
<tr id="add_new_class">
<td style="width:30%"><strong>Classe:</strong>
<select name="var_class[]">
<option value="A"><A</option>
<option value="B"><B</option>
<option value="C"><C</option>
</select>
</td></tr>
</table>
Then my jQuery to clone the select, using the ID:
$(document).on('click',"#add_line_class", function(){
var content = $('#add_new_class').clone(true);
$('#add_new_class').after(content);
});
Till now everything ok and it clones, but I want to pass the values through the POST of PHP, for receive in the next step/page. It passes well the first select (php original select), but doesn't pass the jQuery values (the clone).
Do I need to use post by ajax or something ? or any other idea to solve the problem?
Thanks.
i tried with your code.It works well cloning of elements and POST
data of cloned elements.If you want to get the POST
values of data when click on submit button try like this in your php code
if(isset($_POST['submit']))
{
for($i=0;$i<count($_POST['var_class']);$i++)
{
$rows[$i]['item_name'] = $_POST['var_class'][$i];
}
foreach($rows as $row)
{
print_r($row);
}
}
In your HTML
try to change like this.
<input type="button" onClick="javascript:submit_form();" value="Passo 2 >>" style="width:100px"/>
In your JavaScript
write like this
function submit_form()
{
// You can do here validations
document.form1.action='test.php?step=2';
document.form1.submit();
}
Then it will works. Please try like that.
If this code not resolves your problem please explain more.So that i can help you. Thanks.