基于radiobutton响应之一启用textarea

时间:2014-02-14 09:14:41

标签: javascript

我尝试根据四个textarea

中的一个选择启用radio buttons.
<div id="Response">
   <label><input type="radio" name="Radi4.19" value="Y" id="Radio_4.19_0">Yes</label>
   <label><input type="radio" name="Radi4.19" value="N" id="Radio_4.19_1">No</label>
   <label><input type="radio" name="Radi4.19" value="NS" id="Radio_4.19_2">Not Seen</label>
   <label><input type="radio" name="Radi4.19" value="NA" id="Radio_4.19_3">Not Applicable</label>
</div>

<span id="responseSupplement">
  <div id="Comment">
   <label for="Comment">Comment:</label>
   <textarea name="comment" rows="6" style="width: 530px;" id="Comm4.19" placeholder="Enter comments here ..."></textarea>
   </div>

<div id="Observation">`
    <label for="Observation">Observation:</label>`
    <textarea name="observation" rows="6" disabled="disabled" id="Obs4.19" style="width: 530px;" placeholder="Enter text of observation here ..."></textarea>
</div>
</span>

我能够根据二元选择创建所需的功能:

<script type="text/javascript">

function enable(val)
{if(val)document.f1.feedback.setAttribute("disabled",val)
else
document.f1.feedback.removeAttribute("disabled",val)}
</script>

<form name="f1" action="" >
<input type="radio" name="rating" value="1" id="green" onclick="enable(0)"/><label for="green">Positive</label><br />
<input type="radio" name="rating" value="0" id="red" onclick="enable(1)" /><label for="red">Negative</label><br />
<textarea name="feedback" rows="6" disabled style="width: 50%;" ></textarea>
</form>

1 个答案:

答案 0 :(得分:2)

您需要阅读已点击的单选按钮的已选中或未选中状态,因为您可以将this作为事件监听器的参数传递。

http://jsfiddle.net/m5n6s/