0

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

2 Answers 2

0

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!

0

<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>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.