最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How do I enabledisable a textbox when a radio button is clicked using javascript? - Stack Overflow

programmeradmin2浏览0评论

I have a radio button with a textbox. How do I enable/disable the textbox using the onclick event of a radio button? That is, if the radio button is selected then the textbox should be enabled or else disabled.

Here is my code below:

<INPUT TYPE="radio" name="type" id="type1">
<input type="text" name="name" value="<?php echo $name?>" onChange="javascript:enableField();"/>

I have a radio button with a textbox. How do I enable/disable the textbox using the onclick event of a radio button? That is, if the radio button is selected then the textbox should be enabled or else disabled.

Here is my code below:

<INPUT TYPE="radio" name="type" id="type1">
<input type="text" name="name" value="<?php echo $name?>" onChange="javascript:enableField();"/>
Share Improve this question edited Oct 30, 2013 at 20:15 James-Jesse Drinkard 15.7k16 gold badges118 silver badges140 bronze badges asked Feb 17, 2010 at 7:52 HulkHulk 34.2k64 gold badges150 silver badges217 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3
<input type="radio" name="type" id="type1" onclick="toggleTextbox(this);" />
<input type="text" name="name" value="<?php echo $name?>" id="name1" />

<script type="text/javascript">
function toggleTextbox(rdo) {
    document.getElementById("name1").disabled = !rdo.checked;
}
</script>
发布评论

评论列表(0)

  1. 暂无评论