Reputation: 19
I want create textarea with javascript when I click on the "yes" radio button in a appropriate div place with id?
<div class="controls">
<input type="radio" name="name" id="optionsRadios" value="no" checked><b>NO</b>
<input type="radio" name="name" id="optionsRadios" value="yes" ><b>YES</b>
</div>
<div id="positiontext"></div>
help me
Upvotes: 0
Views: 6041
Reputation: 288
i think you should need to do this by using gome function which are specially made for this:
<div class="controls">
<input type="radio" name="name" id="optionsRadios" value="no" checked><b>NO</b>
<input type="radio" name="name" id="optionsRadios" value="yes" onclick="addtxt();" ><b>YES</b>
</div>
<div id="positiontext"></div>
var addtxt = function(){
var positiontext(parent) = document.getElementById("positiontext");
var textarea(child) = document.createElement("textarea");
textarea(child).addAttribute("style", "(some properties)") //there are other ways also to add some attribute but for now use this
positiontext(parent) .appendChild("textarea(child)")
}
Upvotes: 0
Reputation: 388316
Instead of creating & removing the textarea, I would set its display like
function nameChange(el) {
document.getElementById('positiontext').style.display = el.value == 'yes' ? '' : 'none';
}
<div class="controls">
<input type="radio" name="name" id="optionsRadios" value="no" onchange="nameChange(this)" checked /><b>NO</b>
<input type="radio" name="name" id="optionsRadios" value="yes" onchange="nameChange(this)" /><b>YES</b>
</div>
<div id="positiontext" style="display: none;">
<textarea name=""></textarea>
</div>
Upvotes: 1
Reputation: 3090
Try this by adding the onclick event to the yes radio button,
<input type="radio" name="name" id="optionsRadios" value="yes" onchange="addDIV()">
In javascript,
<script>
function addDIV() {
document.getElementById('positiontext').innerHTML = "<input type='textarea' name='myText' />"
}
</script>
Upvotes: 0