jquery - Rails Javascript onsubmit validate() Uncaught ReferenceError: validate is not defined -


i have form of following characteristics:

= nested_form_for reservation, html: { onsubmit: "return validate()"} ... 

and following file reservation.js:

jquery(function() {   $('div.modal').on('loaded.bs.modal', function(e) {     ...some code...   });   $('div.modal').on('shown.bs.modal', function(e) {     ...some code...   });    function validate(){     var guests = 0;     $('.guests-input').each(function(i, e){       guests = guests + $(e).val();     });     if (guests < 1){       alert('sum of percentage must 100');       return false;     }     return true;   } }); 

but, when click submit button error:

uncaught referenceerror: validate not defined

i don't know should define it. i've searched other questions couldn't solve problem them. i'm not entirely sure either should look.

i'll edit more information if needed.

as rory mccrossan says on comment, solution move out validate() definition outside jquery's document.ready handler.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -