javascript - On change event of dropdown ruby on rails -


i'm creating website, , @ registration page users required fill in gender , age before continuing. code such:

<%= form_for(@user) |f| %>           <!--some other stuff-->            <%= f.label :gender %>           <%= f.select :gender, options_for_select(['m', 'f', 'n/a']), :id => "gender", :include_blank => "please select..." %>            <%= f.label :age %>           <%= f.select :age, (17..75), :id => "age", :include_blank => "please select..." %>           <br>           <br>           <div class='center'>             <%= f.submit "save , continue", class: "btn btn-large btn-primary", :disabled => true %>           </div>       <% end %>     </div> 

generated html:

<form accept-charset="utf-8" action="/users" class="new_user" id="new_user" method="post"><div style="display:none"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" //other stuff></div>           <label for="user_gender">gender</label>           <select id="user_gender" name="user[gender]"><option value="">please select...</option> <option value="m">m</option> <option value="f">f</option> <option value="n/a">n/a</option></select>            <label for="user_age">age</label>           <select id="user_age" name="user[age]"><option value="">please select...</option> <option value="17">17</option> // skipped <option value="75">75</option></select>           <br>           <br>           <div class="center">             <input class="btn btn-large btn-primary" disabled="disabled" name="commit" type="submit" value="save , continue">           </div> </form> 

javascript:

$(document).ready(function () {         $select_age = $("select#user_gender");         $select_gender = $("select#user_age");          var check_value = function () {             alert("asdf");             if ($select_gender.val() !== "" && $select_age.val() !== "") {                 $("input[name='commit']").removeattr("disabled");             }         };          $select_age.change(check_value()) // i've tried onchange          $select_gender.change(check_value())     }); 

whenever select new option dropdown, should alert says "asdf". doesn't happen. why?

try below code

$select_age.on("change", check_value()) // i've tried onchange  $select_gender.on("change", check_value()) 

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 -

ios - Change Storyboard View using Seague -