The form does not work in the sharing method

I submit my form when the onchange event of my drop down is fired using jQuery.

The first time it works, but the second time the onchange event onchange not onchange . It is not even part of the jQuery script. How can I solve this problem? And how do I load jQuery in the onload ? My jquery code:

  $('#statusId').bind('change',function() { alert($(this).val()); $('#statusHiddenId').val($(this).val()); $('#layoutFormID').attr('method', 'POST'); $('#layoutFormID').attr('action', '/sample'); $('#layoutFormID').submit(); }); 

HTML CODE:

 select(name='status',rel = "external", id='statusId', data-theme='a', data-icon='gear', data-native-menu="false") option(value='0') All Status option(value='1') New option(value='2') Verified option(value='3') KYC Completed option(value='4') Loan Sanctioned option(value='5') Loan Disbursed option(value='6') Closed option(value='7') Archive 
+4
source share
2 answers

Try the following:

put this code in javascript function and call it every time through onchange.

 function MyFunction() { $('#statusHiddenId').val($(this).val()); $('#layoutFormID').attr('method', 'POST'); $('#layoutFormID').attr('action', '/sample'); $('#layoutFormID').submit(); } 

onchange = MyFunction ();

 specify onchange function in select box. 
0
source

If you said "loading a document" when you say onload , then the code:

 $(function(){ // your code here }); 

If your script replaces the contents of the form, you need to bind the handler further with a chain, for example:

(if you have a container element with the identifier "container", which is not replaced)

 $('#container').on('change', '#statusId', function(event) { // your code here }); 

It is assumed that you are using jQuery 1.7 or higher.

0
source

Source: https://habr.com/ru/post/1436940/


All Articles