Попробуйте приведенный ниже код. Я добавил детали в код.
Код jQuery.
clone.find("input, select").attr("disabled", false).val("");
//Add the code to replace the name attr of input field.
clone.find("input,select").each(function() {
/*When click on add row button replace the name attr
second row to reason[1][] - will append all the option value of second row
third row to reason[2][] - will append all the option value of third row
----
etc
*/
this.name = this.name.replace(/\[(\d+)\]/,function(str,p1){return '[' + (parseInt(p1,10)+i) + ']'});
});
HTML-код.
<!-- before you are adding all selected item in single array reason, change the name attribute to reason[0][] -->
<select class="selectReason" name="reason[0][]">
<option value="1">AAAA</option>
<option value="2">BBBB</option>
<option value="3">CCCC</option>
<option value="4">DDDD</option>
<option value="5">EEEE</option>
</select>
</td>
PHP-код.
if(isset($_POST['name'])){
$name = $_POST['name'];
$reason = $_POST['reason'];
for($i=0; $i<count($name); $i++){
//value of name by row
echo $name[$i].'<br/>';
//Onsubmit get the value of select option seperated by each row
echo "<pre>";
print_r($reason[$i]);
}
}
Выход -
AAA
Array
(
[0] => 1
[1] => 2
[2] => 3
)
BBB
Array
(
[0] => 2
[1] => 3
[2] => 4
)
CCC
Array
(
[0] => 1
[1] => 2
[2] => 3
)