javascript - add more form element logic with radio input -


i wrote code user can click add more duplicate form elements , add values. it's working fine except radio inputs. stuck. how can solve problem in easy way? below code.

<div id="dup">     <p>         athlete name:<br>         <select name="athlete_name" id="athlete_name[]">             <option value="" selected="selected">choose user</option>             <option value="2">candice falzon</option>             <option value="5">athlete example</option>         </select>     </p>      <p>         sex:          <input type="radio" name="athlete_sex" value="male">male          <input type="radio" name="athlete_sex" value="female">female     </p> </div> 

i can not take athlete_sex array .

sometimes jquery can stickler closing tags. fixed them , works:

    var clone = $('#dup:last').clone();        window.addanother = function() {        clone.find('input').attr('name', 'athlete_sex' + ($('#wrapper').children().length + 1));        $('#wrapper').append(clone);        clone = clone.clone();      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="wrapper">    <div id="dup">      <p>athlete name:        <br />        <select name="athlete_name" id="athlete_name[]">          <option value="" selected="selected">choose user</option>          <option value="2">candice falzon</option>          <option value="5">athlete example</option>        </select>      </p>        <p>sex:        <input type="radio" name="athlete_sex" value="male" />male        <input type="radio" name="athlete_sex" value="female" />female</p>    </div>  </div>  <button onclick="addanother()">add another</button>


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -