0

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

3 Answers 3

1

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>

Sign up to request clarification or add additional context in comments.

Comments

0

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>

FIDDLE DEMO

3 Comments

why do you want to use innerHTML ?
I want create textarea with javascript when I click on the "yes" radio button?
what i mean is that, using innerHTML is a bad thing because for suppose if you want to all more text area to any parent node then first you have to write existing code then you have to add further code and at some point it slowers our application..
0

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>

javascript:

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)")
}

1 Comment

Thanks to all of you :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.