JavaScript display textboxes when radio button selected

this is my html code :

<div>
    <label for="accompanying_person" class="col-sm-4 col-form-label">Select number of accompanying person</label>
       <div class="col-sm-8">
               <input type="radio" name="accompanying_person" id="accompanying_person" value="1"> 1
               <input type="radio" name="accompanying_person" id="accompanying_person" value="2"> 2
               <input type="radio" name="accompanying_person" id="accompanying_person" value="3"> 3
       </div>
 </div>
Answer:1

try this code

$(document).ready(function() {

  $(this).click(function() {
    $('#textbox').html('');
    var val = $('input[name=accompanying_person]:checked').val();
    for (var i = 1; i <= val; i++) {
      $('#textbox').append('<input type="text" id="' + i + '"><br>');
    }
  });
});
input {
  margin-bottom: 3px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <label for="accompanying_person" class="col-sm-4 col-form-label">Select number of accompanying person</label>
  <div class="col-sm-8">
    <input type="radio" name="accompanying_person" id="accompanying_person" value="1"> 1
    <input type="radio" name="accompanying_person" id="accompanying_person" value="2"> 2
    <input type="radio" name="accompanying_person" id="accompanying_person" value="3"> 3

  </div>
  <div id="textbox"></div>
</div>
Answer:2

I want user mouse position while the user is holding down the mouse button continuously? I try to do the with following code: $(div).mousedown(function(eventObj){ console.log(eventObj.clientX); ...

I want user mouse position while the user is holding down the mouse button continuously? I try to do the with following code: $(div).mousedown(function(eventObj){ console.log(eventObj.clientX); ...

I am using Selenium WebDriver and coding in Java. In a code I need to scroll down to a specific element in the web page for clicking it. I am using JavascriptExecutor command. My question is how will ...

I am using Selenium WebDriver and coding in Java. In a code I need to scroll down to a specific element in the web page for clicking it. I am using JavascriptExecutor command. My question is how will ...

I'd like to bind 2 Angular model variables to a range input element according to the following: update first model variable for every change of the range input update second model variable after x ms ...

I'd like to bind 2 Angular model variables to a range input element according to the following: update first model variable for every change of the range input update second model variable after x ms ...

  1. input bind variables

Given two points: const point1 = {x: 100, y: 0.95} const point2 = {x: 75, y: 1.05} I need to know the value of y when x equals some arbitrary value. Please assume a linear relationship exists. For ...

Given two points: const point1 = {x: 100, y: 0.95} const point2 = {x: 75, y: 1.05} I need to know the value of y when x equals some arbitrary value. Please assume a linear relationship exists. For ...

  1. function point line of code
  2. point function line
  3. function point and line of code difference