jquery - javascript ul button dropdown crashes after if doing more than 1 button -


so have button drop down list want users select choice, , button return users selection.pretty straight forward, tested on jsfiddle , works great. using ruby on rails btw, i'm not sure if might conflicting way rails handle javascript actions.

heres code:

  <%= form_for(@user, :html => {:class => 'form-horizontal'}) |f| %>   <fieldset>    <p>do have experience in business? if yes, select 1 of following: <div class="input-group">   <div class="input-group-btn btn-group">     <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">select 1 <span class="caret"></span></button>     <ul class="dropdown-menu">       <li ><a href="#">entrepreneurship</a></li>       <li ><a href="#">investments</a></li>       <li ><a href="#">management</a></li>       <li class="divider"></li>       <li ><a href="#">all of above</a></li>     </ul>   </div><!-- /btn-group -->   <%= f.text_field :years_business , :class => "form-control", :placeholder => "years of experience" %>  </div> 

now there 2 more of these, , happens if select item first time dropdown list, works great. moment select same button/or new button, page kind of refreshes, selected value not show after list drops down , user selects value. viewed page source , added additional javascript src , types, still doesnt work. jquery code:

   jquery(function ($) { $('.input-group-btn .dropdown-menu > li:not(.divider)').click(function(){     $(this).closest('ul').prev().text($(this).text()) }) }); 

any suggestions causing problem?? jsfiddle link here:

http://jsfiddle.net/w4s8u/7/

check if handler function fix issue:

 $('.input-group-btn .dropdown-menu > li > a').click(function(e){             e.preventdefault();             $(this).closest('ul').prev().text($(this).text())         }) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -