-2

i want to know how add two events in the same ajax

 <script type="text/javascript">
$(document).ready(function(){

    $('#department').on('change',function(){
        var deptID = $(this).val(); console.log(deptID);
        if(deptID){
            $.ajax({
                type:'POST',
                url: BASE_URL+'User/listHospital',
                data:'id='+deptID,
                success:function(html){
                    $('#hospital').html(html);
                    $('#specialisation').html('<option value="">Select hospital</option>');
                         $('#special').html('<option value="">Select hospital</option>');
               }
            }); 
</script>

here i had used on change event i want to add one more event on focus what should i do for it please help

  • You should check the manual. – jeroen Feb 26 '18 at 08:04
  • duplicate, check this https://stackoverflow.com/questions/2534089/jquery-multiple-events-to-trigger-the-same-function – Farrokh Feb 26 '18 at 08:06
  • 2
    Possible duplicate of [jQuery multiple events to trigger the same function](https://stackoverflow.com/questions/2534089/jquery-multiple-events-to-trigger-the-same-function) – Farrokh Feb 26 '18 at 08:07

1 Answers1

0

I don't completely understand your question but, is this how you want it?

$("#department").on({

    'change': function(){
          //ajax here
    }

    'focus': function(){
          //ajax here
    }

});
vanir
  • 349
  • 3
  • 11