Php 单选按钮文本区
我有这张调查表,效果很好。我只需要改变这一个问题。基本上有两个单选按钮用于回答“是”和“否”,并在其下方有一个文本区域。现在我希望文本区域被锁定,除非用户选择“是”单选按钮,然后他们可以在文本区域中键入“是”的原因 我环顾四周,尝试了一下这个功能,但它似乎不起作用Php 单选按钮文本区,php,html,Php,Html,我有这张调查表,效果很好。我只需要改变这一个问题。基本上有两个单选按钮用于回答“是”和“否”,并在其下方有一个文本区域。现在我希望文本区域被锁定,除非用户选择“是”单选按钮,然后他们可以在文本区域中键入“是”的原因 我环顾四周,尝试了一下这个功能,但它似乎不起作用 函数验证(){ var radioYes=document.getElementById('radioYes'); var textarea=document.getElementById('question5comment');
函数验证(){
var radioYes=document.getElementById('radioYes');
var textarea=document.getElementById('question5comment');
if(radioYes.checked&&question5comment.value.length<1){
提醒('请输入问题5的原因');
问题5关注焦点();
返回false;
}
}
功能切换(值){
document.getElementById('question5comment')。disabled=值;
}
5.您是否在使用其他非特许经营服务中心?
*如果是的话,除了价格之外,还有其他原因吗
对
您的语法错误:
不必要的您的语法错误:
不必要的您有许多缺少的代码!像id不存在一样,函数被创建,但没有初始化调用它
<script>
function validate(t) {
var question5comment = document.getElementById('question5comment');
if (t.checked && question5comment.value.length < 1) {
alert('Please enter your reason for Question 5.');
question5comment.focus();
return false;
}
toggle(t.value);
}
function toggle(value) {
document.getElementById('question5comment').disabled = (value == "Yes") ? false : true;
}
</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" onchange="validate(this)" required>Yes
<br>
<input type="radio" name="question5" onchange="validate(this)" value="No" required>No
<br>
<textarea name="question5comment" id="question5comment" rows="5" cols="40" required></textarea>
功能验证(t){
var question5comment=document.getElementById('question5comment');
如果(t.checked&&question5comment.value.length<1){
提醒('请输入问题5的原因');
问题5关注焦点();
返回false;
}
切换(t值);
}
功能切换(值){
document.getElementById('question5comment').disabled=(值=“Yes”)?false:true;
}
5.您是否在使用其他非特许经营服务中心?
*如果是的话,除了价格之外,还有其他原因吗
对
不
您有许多缺少的代码!像id不存在一样,函数被创建,但没有初始化调用它
<script>
function validate(t) {
var question5comment = document.getElementById('question5comment');
if (t.checked && question5comment.value.length < 1) {
alert('Please enter your reason for Question 5.');
question5comment.focus();
return false;
}
toggle(t.value);
}
function toggle(value) {
document.getElementById('question5comment').disabled = (value == "Yes") ? false : true;
}
</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" onchange="validate(this)" required>Yes
<br>
<input type="radio" name="question5" onchange="validate(this)" value="No" required>No
<br>
<textarea name="question5comment" id="question5comment" rows="5" cols="40" required></textarea>
功能验证(t){
var question5comment=document.getElementById('question5comment');
如果(t.checked&&question5comment.value.length<1){
提醒('请输入问题5的原因');
问题5关注焦点();
返回false;
}
切换(t值);
}
功能切换(值){
document.getElementById('question5comment').disabled=(值=“Yes”)?false:true;
}
5.您是否在使用其他非特许经营服务中心?
*如果是的话,除了价格之外,还有其他原因吗
对
不
有效的方法就是改变正确与错误。但我希望只有在他们尝试提交时,在文本区域中不键入任何内容时,警报才会弹出。这可能吗,先生?是的,在您的提交处理程序中,检查值的长度,然后如果是。完美的先生,我已全部设置。最后一件事是,默认情况下我可以锁定textarea吗?因此,当表单打开时,文本区域是locked@EternalJ只需添加textarea.disabled=true代码>在开始处<代码>:)
只要改变左右的真与假就行了。但我希望只有在他们尝试提交时,在文本区域中不键入任何内容时,警报才会弹出。这可能吗,先生?是的,在您的提交处理程序中,检查值的长度,然后如果是。完美的先生,我已全部设置。最后一件事是,默认情况下我可以锁定textarea吗?因此,当表单打开时,文本区域是locked@EternalJ只需添加textarea.disabled=true代码>在开始处<代码>:)