我試着去分配指向每個陣列所以在我的代碼中的每個「主題」,我想Q1,Q2,Q3和Q4,爲不同webpages.So時提交按鈕的不同環節被按下的用戶將被帶到網頁。 因此,例如,用戶將轉到網頁,點擊主題,點擊一個問題,當他們點擊提交時,他們將被帶到問題頁面(.html或其他)。如何分配指向數組
var subjects = new Array("English", "Irish", "Maths", "German", "History", "Business", "Geogrpahy");
var questions = new Array();
questions["English"] = new Array("Q1", "Q2", "Q3", "Q4");
questions["Irish"] = new Array("Q1", "Q2", "Q3", "Q4");
questions["Maths"] = new Array("Q1", "Q2", "Q3", "Q4");
questions["German"] = new Array("Q1", "Q2", "Q3", "Q4");
questions["History"] = new Array("Q1", "Q2", "Q3", "Q4");
questions["Business"] = new Array("Q1", "Q2", "Q3", "Q4");
questions["Geogrpahy"] = new Array("Q1", "Q2", "Q3", "Q4");
function resetForm(theForm) {
/* reset subjects */
theForm.subjects.options[0] = new Option("Please select a subject", "");
for (var i = 0; i < subjects.length; i++) {
theForm.subjects.options[i + 1] = new Option(subjects[i], subjects[i]);
}
theForm.subjects.options[0].selected = true;
/* reset questions */
theForm.questions.options[0] = new Option("Please select a question", "");
theForm.questions.options[0].selected = true;
}
function updateModels(theForm) {
var make = theForm.subjects.options[theForm.subjects.options.selectedIndex].value;
var newModels = questions[make];
theForm.questions.options.length = 0;
theForm.questions.options[0] = new Option("Please select a question", "");
for (var i = 0; i < newModels.length; i++) {
theForm.questions.options[i + 1] = new Option(newModels[i], newModels[i]);
}
theForm.questions.options[0].selected = true;
}
resetForm(document.autoSelectForm);
<form name="autoSelectForm" action="" method="post">
<select size="1" name="subjects" onchange="updateModels(this.form)">
</select>
<select size="1" name="questions" onclick="">
</select>
<input type="submit">
</form>
嗨,德克斯特這是迄今爲止最好的答案。但是你沒有解釋如何給每個問題提供不同的鏈接。在這裏,您已將每個選項鍊接到相同的鏈接 - example.com。 – AaronC
@AaronC關於每一個問題的不同環節,比方說,你將用戶重定向到'results.php',當你提交一個表單以'GET'方法,你會看到類似'results.php?主題=英語和季= Q3',這意味着它是一個不同的鏈接,但是在同一個文件上執行,所以在你的'results.php'中,你可以使用'$ _GET ['subject']'和$ $獲得'subject'和'quarter' _GET ['quarter']'來自'url'。因此,這些將是您在從數據庫中提取問題或其他問題時必須使用的變量。 – dexterb
我看到你來自哪裏,但這不是我要找的。問題頁面將擁有自己的.php鏈接。我想要的是每個主題的Q1,Q2,Q3和Q4的href值爲... .html。這將使我未來更容易。我不打算讓這個頁面連接到我的mysql數據庫..這個下拉的目的是將用戶鏈接到確切的.php頁面,然後連接到每個問題的數據庫 – AaronC