Reputation: 5247
Dynamically added select multiple drop down options using the perl cgi. When I submit the form the select fields are not getting passed via post data.
Submit jquery handler
$("#srch_id_form").submit(function()
{
alert('Form is submitting');
$(this).serialize();
return true;
});
});
Select multiple dropdown in the dynamic html
<form id="srch_id_form" name="srch_form" method="post" action="testpost.cgi" >
** <!-- Selected drop down -->
<select id="srch_id_opt_selchanges" size="4" name="srch_n_selchanges">
<option value="label" readonly="readonly"> *** Press Add Button to create the selection *** </option>
</select>
**
</form>
Jquery for adding dynamically adding select options to the id "#srch_id_opt_selchanges" when a add button is clicked
$('#srch_addimg').click(function() {
var str="";
var selTxt="";
var selVal="";
var txtVal="";
selTxt= $("#srch_chgdropdown option:selected").text();
selVal=$("#srch_chgdropdown option:selected").val();
console.log("test value:" + $("#srch_chgdropdown option:selected").text() +"---");
txtVal=$("#srch_filltxt").val();
if(!txtVal) {
alert('Please fill the Value for ' + selTxt);
}
else {
subVal=selTxt+"="+txtVal;
$("#srch_id_opt_selchanges").append("<option value='" + subVal+"'>" +subVal+ "</option>");
}
});
Upvotes: 0
Views: 76
Reputation: 722
I think you need set default value before submit:
$("#srch_id_opt_selchanges").append("<option selected='selected' value='" + subVal+"'>" +subVal+ "</option>");
Upvotes: 1