[英]How to set selected value of 's:radio' button in 's:textarea' with JavaScript?
I need to set 's:textarea' value which is selected in 's:radio' button.我需要设置在 's:radio' 按钮中选择的 's:textarea' 值。
I am currently using the code below to do it.我目前正在使用下面的代码来做到这一点。 But it always set the 'In test' value in 's:textarea' which is the first value in 's:radio' button list.但它总是在 's:textarea' 中设置 'In test' 值,这是 's:radio' 按钮列表中的第一个值。
function handleCommentChange()
{
var comment = document.getElementById('comment');
var radioComment1 = document.getElementById('radio1');
comment.value = radioComment1.value;
}
<td>
<s:radio id="radio1" name="radio1" list="#{'In test':'In test','Defect':'Defect','Pass':'Pass', 'Fail':'Fail' }"
onclick="javascript:handleCommentChange();" ></s:radio>
<br></td>
<td><s:textarea id="comment" name="comment" cols="25" rows="5"></s:textarea></td>
Please tell how I can set the selected value of 's:radio' button in 's:textarea'.请告诉我如何在“s:textarea”中设置“s:radio”按钮的选定值。
Pass a reference to the clicked radio in to your handleCommentChange() function.将单击的收音机的引用传递给您的 handleCommentChange() function。 You can pass this
, which will give the function a reference to the radio element and let you access all of its properties, etc., or you can pass this.value
directly and have the function assign that string to your textarea.您可以传递this
,这将为 function 提供对 radio 元素的引用并让您访问其所有属性等,或者您可以直接传递this.value
并让 function 将该字符串分配给您的文本区域。 I prefer to pass this
to allow for future expansion needing access to other properties:我更喜欢通过this
以允许将来需要访问其他属性的扩展:
function handleCommentChange(aRadio) {
document.getElementById('comment').value = aRadio.value;
}
<s:radio ... onclick="handleCommentChange(this);">
The other way to do it is to setup a loop to go through each radio button and check which one has its checked property set to true.另一种方法是通过每个单选按钮设置到 go 的循环,并检查哪个单选按钮的已选中属性设置为 true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.