我目前正在使用一組選項的窗體。在一些問題上,用戶可以選擇「其他」選項。我試圖讓它看起來只有「其他」被選中(我已經得到這個工作的第一個問題,但沒有其他人)。我也試圖只在他們選擇它時才需要這個輸入,以便他們不能提交已選擇「其他」的表單並將其留空。HTML窗體:需要其他輸入只有在選擇了其他輸入的情況下
這是我的HTML和JavaScript製作時選擇其他文本輸入顯示:
<label for="Accom">Question</label>
<table>
<tr>
<td><select name="Accom">
<option value="">Select...</option>
<option value="Handicapped">Handicap Accessibility</option>
<option value="Hearing Impaired">Hearing Impaired</option>
<option value="Visually Impaired">Visually Impaired</option>
<option value="OtherAccom">Other</option>
</select>
</td>
</tr>
<tr>
<td colspan="4">
<label style="" id="other">If Other, Please Specify
<input type="text" name="Other_Accom" size="20"></label></td><tr></table>
。
window.onload=function() {
var other = document.getElementById('other', 'otherAccom','otherDiet');;
other.style.display = 'none';
document.getElementsByName('Title', 'Diet', 'Accom')[0].onchange = function() {other.style.display =(this.value=='Other')? '' : 'none'};
我也試圖得到這個工作的複選框形式。
<label for="Interests">Question</label><br>
<input class="checkbox2" TYPE="checkbox" NAME="formInterests[]" required value="Use Cases ||" />Use Cases<br>
<input class="checkbox2" TYPE="checkbox" NAME="formInterests[]" required value="Other" />Other<br>
<label style="" id="other">If Other, Please Specify
<input type="text" name="Other_Interests" size="20"></label>
非常感謝!編輯1:當我嘗試和複製功能,它停止工作的一切。
window.onload=function() {
var other = document.getElementById('other', 'otherAccom', 'otherDiet');;
other.style.display = 'none';
document.getElementsByName('Title')[0].onchange = function() {other.style.display = (this.value=='Other')? '' : 'none'};
};
window.onload=function() {
var otherDiet = document.getElementById('other', 'otherAccom', 'otherDiet');;
otherDiet.style.display = 'none';
document.getElementsByName('Diet')[0].onchange = function() {otherDiet.style.display = (this.value=='OtherDiet')? '' : 'none'};
};
我試過這樣做,當我創建單獨的功能,我有工作原來的一個停止工作,所以他們都沒有工作。有什麼建議麼? – AngeloS
@AngeloS很難說,也許你可以更新代碼? – Johannes
我更新了它,希望能夠展示我的意思。 – AngeloS