[英]dynamic form using jquery ajax load posting to the same form
I want to load form dynamically using following : HTML : 我想使用以下内容动态加载表单:HTML:
<div id="add_new" style="display:none">
<form id="addrecord_form" name="addrecord_form" method="post" action="">
<label>Type:</label>
<select name="type_select" id="type_select">
<option value="A">Type A form </option>
<option value="B">Type B form </option>
Javascript : Javascript:
$("#type_select").change(function() {
$("#add_new_field").html("");
if ( $(this).val() == "A") {
$.get("/form_type_a", function(data) {
$("#add_new_field").load(data);
});
}
if ( $(this).val() == "B") {
$.get("/form_type_b", function(data) {
$("#add_new_field").load(data);
});
}
$('#addrecord_form').submit(function(eve)
{
eve.preventDefault();
$.ajax({url: "submit_a_record",
type: "POST",
dataType: "html",
data: $('#addrecord_form').serialize(),
success: function(html) { processForm(html); }
});
});
Loading the form is fine, but if users change the select box to option B and submit the form they will submit the form A as well as from B. 加载表单很好,但是如果用户将选择框更改为选项B并提交表单,则他们将同时提交表单A和B。
How do I unload form A when users already select form B so that they dont submit content of form A? 当用户已经选择了表单B而不提交表单A的内容时,如何卸载表单A?
为什么不具有两种形式,然后在select元素的onchange中使用您的jquery(或只是直接的javascript)显示您想要的一种形式?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.