jquery动态表单提交

时间:2013-12-11 05:23:01

标签: jquery

使用perl cgi动态添加选择多个下拉选项。当我提交表单时,选择字段不会通过发布数据传递。

提交jquery处理程序

$("#srch_id_form").submit(function()
        {
         alert('Form is submitting');
        $(this).serialize();
         return true;
        });


});

在动态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用于在单击添加按钮时向id“#srch_id_opt_selchanges”添加动态添加选项选项

$('#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>");
    }

 });

1 个答案:

答案 0 :(得分:1)

我认为您需要在提交之前设置默认值:

  $("#srch_id_opt_selchanges").append("<option selected='selected' value='" + subVal+"'>" +subVal+ "</option>");
相关问题