1

I would like to create two event by reusing the code of a method, this is my code, how could i able to create two event for single element using jQuery

$('#country_ID').on({
    blur : val (),
    submit:val () 
});

function val() {
    if ($('#country_ID').val() == '')
    {
        formval = false;
        alert(formval.toString());
    }
}

Thanks in Advance..

Vengat_93
  • 759
  • 1
  • 5
  • 10
  • Possible duplicate of [jQuery multiple events to trigger the same function](http://stackoverflow.com/questions/2534089/jquery-multiple-events-to-trigger-the-same-function) – Joshua Terrill Nov 26 '16 at 06:15

2 Answers2

2

The simplest way to do it is as follows:

$('#country_ID').bind('blur submit', function (e) {
    // This is your combined function
    val(); //calling the required function
});
vijayP
  • 11,432
  • 5
  • 25
  • 40
0

The jQuery.on is clear about this, the firs parameter is a list of events

Your case should be like:

$('#country_ID').on( "blur submit", val )
phobia82
  • 1,257
  • 8
  • 10