我有两个静态选择框,其中一个由mysql数据库填充。 这些是通过ajax发送到PHP脚本以在列表上添加项目。这个表单包含一个提交按钮,所有这一切都正常。
然后我用ajax run dependent select框替换了框B(Select Box B根据Select Box A的结果填充)。这本身也很好。但是...... 现在提交按钮不起作用,我不知道为什么?
谁能告诉我该怎么做? (会有很多流浪的id和课程,我一直在玩,请原谅这些)
三江源!
AJAX根据SELECT A
的结果向下移动选择框B<script>
$(document).ready(function($) {
var list_select_id = 'A';
var list_target_id = 'B';
var initial_target_html = '<option value="">Please select ...</option>'; //Initial prompt for target select
$('#'+list_target_id).html(initial_target_html); //Give the target select the prompt option
$('#'+list_select_id).change(function(e) {
//Grab the chosen value on first select list change
var selectvalue = $(this).val();
//Display 'loading' status in the target select list
$('#'+list_target_id).html('<option value="">Loading...</option>');
if (selectvalue == "") {
//Display initial prompt in target select if blank value selected
$('#'+list_target_id).html(initial_target_html);
} else {
//Make AJAX request, using the selected value as the GET
$.ajax({url: 'http://www.mypropertyviewing.com/Client_order_form_v1.1/selector.php?svalue='+selectvalue,
success: function(output) {$('#'+list_target_id).html(output);}
});
}
});
});
</script>
FORM WITH SELECT BOXES A B C
<form class="add-new-task" autocomplete="off" method="post" name="login_form">
<div>
<select name="A" id="A">
<option value="">Please select..</option>
<option value="Chemical">Chemical</option>
<option value="Hardware">Hardware</option>
</select>
<select name="B" id="B"></select>
</div>
</br>
<div class="box300">
<p>Select Quantity</p>
<select class="box250" name="C">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<input type='submit' class ="submitbox" value='Add to order' >
</form>
AJAX从选择框B&amp;发送输出C TO PHP SCRIPT(正在运行)
<script>
// Call the add_task function
add_task();
delete_task(); // Call the delete_task function
function add_task() {
$('.add-new-task').submit(function(){
var new_taskA = $('.add-new-task select[name=B]').val();
var new_taskB = $('.add-new-task select[name=C]').val();
if(new_taskA != '') {$.post('add-task.php', { sendA: new_taskA, sendB: new_taskB }, function( data ) {$(data).appendTo('.task-list ul').hide().fadeIn();
delete_task();
});
}
return false;
});
}
function delete_task() {
$('.delete-button').click(function(){
var current_element = $(this);
var id = $(this).attr('id');
$.post('delete-task.php', { task_id: id }, function() {
current_element.parent().fadeOut("fast", function() { $(this).remove(); });
});
});
}
</script>