我對此很新,所以這可能不是解決此問題的最佳方法。基本上,我試圖在提交表單時運行三個.php文件中的一個。我運行的.php文件應取決於用戶從ID =「periodDisplay」的選擇字段中選擇的值。真的很感謝一些幫助。根據從選擇標記中選擇的選項選擇表單操作
<script>
function onSubmitForm(){
if(document.getElementById("periodDisplayed").selectedIndex == 'This Week')
{
return document.selectDisplay.action ="thisWeek.php";
}
else if(document.getElementById("periodDisplayed").selectedIndex == 'This Month')
{
return document.selectDisplay.action ="thisMonth.php";
}
else if(document.getElementById("periodDisplayed").selectedIndex == 'All Workouts')
{
return document.selectDisplay.action ="allWorkouts.php";
}
else
{
return document.selectDisplay.action = "index.html";
}
return true;
}
</script>
<form id="selectDisplay" onsubmit="return onSubmitForm();">
I want to see
<select id="unitDisplayed">
<option>Distance</option>
<option>Time</option>
</select>
for
<select id="periodDisplayed">
<option>This Week</option>
<option>This Month</option>
<option>All Workouts</option>
</select>
<input type="submit"></input>
</form>
不是這應該是的document.getElementById( 「periodDisplayed」)。selectedIndex.value – Satya