I want to display an input textbox after choosing one of the radio button selection but I'm having difficulty to do it. For example, I have 3 radio buttons: name, age and phone number. If I choose the name, then the input textbox will display for me to input a name and so on if I choose others. I want to know how to do it using HTML and javascript. Mind to help me, anyone? Thank you.
2 Answers
you can write all things like this.
function show(gender){
console.log(gender);
}
<label for="gender">
<input type="radio" name="gender" onclick="show('male')" value="male"/> male <br />
<input type="radio" name="gender" onclick="show('female')" vlaue="female"/> Female
</label>
thanks!
<label for="name">
<input type="radio" name="gender" onclick="createElements()"/> Male <br />
<input type="radio" name="gender" onclick="createElements()"/> Female
<div id="input"></div>
</label>
<script>
function createElements(){
var input = document.createElement("INPUT");
input.setAttribute("type", "text");
document.getElementById("input").appendChild(input);
}
</script>