【发布时间】:2016-10-30 13:45:47
【问题描述】:
我有这份调查表,效果很好。我只需要改变这一个问题。基本上有 2 个单选按钮用于回答“是”和“否”以及它们下方的文本区域。现在我希望文本区域被锁定,除非用户选择“是”单选按钮,然后他们可以在文本区域中输入“是”的原因。
我环顾四周并尝试了这个功能,但它似乎不起作用。
<script>
function validate() {
var radioYes = document.getElementById('radioYes');
var textarea = document.getElementById('question5comment');
if (radioYes.checked && question5comment.value.length < 1) {
alert('Please enter your reason for Question 5.');
question5comment.focus();
return false;
}
}
function toggle(value) {
document.getElementById('question5comment').disabled = value;
}
</script>
5. Are you using other non-franchise service centres?
<br>
*if yes is there any other reason you would do so other than price
<br>
<input type="radio" name="question5"
value="Yes" required>Yes
<br>
<input type="radio" name="question5"
<value="No" required>No
<br>
<textarea name="question5comment" rows="5" cols="40" required></textarea>
【问题讨论】: