我真的不知道问题出在哪里,但前两个<select>
+ event
对工作,但第三个不是,它几乎是完全一样的第二。
变量“firmName”解析为一个单字串,如果我手动与它的值替换变量,函数工作(但它是通过改变(onload事件触发代替),它绑定到):http://www.frende.me/invoiceBuilder.php
<select id="firm" name="firm"></select>
<select id="client" name="client"></select>
<select id="project" name="project"></select>
<select id="task" name="task"></select>
<p id="results"></p>
<script>
window.onload = (function(){
$.ajax({
/* populates the first <select> with <options> */
});
});
$("#firm").change(function() {
var firmName = "";
$("#firm option:selected").each(function() {
firmName += $(this).text() + " ";
});
$.ajax({
url: '_resources/db_clientworklog_selectField.php',
type: "POST",
data: ({
table: firmName,
column: "client",
}),
success: function(data){
$("#client").html(data);
}
});
})
.change();
$("#client").change(function() {
var firmName = $("#firm").val();
$("#results").text(firmName);
$("#client option:selected").each(function() {
clientName += $(this).text() + " ";
});
$.ajax({
url: '_resources/db_clientworklog_selectField.php',
type: "POST",
data: ({
table: firmName, /* if i replace "firmName" with one of the table's names, like "frende", it works (tho it populates immediately onload) */
column: "project",
}),
success: function(data){
$("#project").html(data);
}
});
})
.change();
</script>
这可能不是问题,但你应该拿出逗号在“列的结尾:“客户端“,”和“列:”项目“,”行,因为他们在数组的末尾。 IE可能是一个真正的问题。 –
你确定firmName是不是未定义?我会在$(“#firm”)。val()之后向第三个更改绑定中发出警报,以确保它实际上获取了值。 –
@bob baddeley:谢谢指出:) – jacob