javascript - Jquery $('input[name=""]').change(function WILL NOT FIRE in Chrome unless there is an uncaught error after it -


so, here's script i've written make inputs dependent on affirmative answer input. in case, 'parent' input radio button.

you can see hides parent divs of inputs when document ready, , waits pertinent option changed before firing logic.

if you'll @ comment near bottom of javascript, you'll see what's been stumping me. if remove if statement, change function not fire. if set variable there not error logged in console, change event not fire.

if change jquery selector $('select').change... event fires, won't work on radio button. changing $('input').change... fails.

<script type="text/javascript"><!--                 $(function(ready){                     $('#input-option247').parent().hide();                     $('#input-option248').parent().hide();                     $('#input-option249').parent().hide();                     $('#input-option250').parent().hide();                     $('#input-quantity').attr('type', 'hidden');                     $('#input-quantity').parent().hide();                     $('input[name="option\\[230\\]"]').change(function() {                         if (this.value == '21') { //if yes, display dependent options                             $('#input-option247').parent().show().addclass('required');                             $('#input-option248').parent().show().addclass('required');                             $('#input-option249').parent().show().addclass('required');                             $('#input-option250').parent().show().addclass('required');                         } else if (this.value == '22') { //if no, hide dependent options                             $('#input-option247').parent().hide().removeclass('required');                             $('#input-option248').parent().hide().removeclass('required');                             $('#input-option249').parent().hide().removeclass('required');                             $('#input-option250').parent().hide().removeclass('required');                         }                     });                     //i don't know why necessary, input.change() event not fire unless it's present.  if set variable, breaks change function above.  if it's not here, breaks change function above.  i'm stumped.                     if(poop){}                  });//--></script> 

i'm hoping see rather obvious tired brain won't see. such simple script, , i'm pulling hair out on seems rather annoying bug.

if selector has special characters need use \\ before characters.

$('input[name="option[230]"]')

should be

$('input[name="option\\[230\\]"]')

see http://api.jquery.com/category/selectors/


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -