我真的不知道問題出在哪裏,但前兩個<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