Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple selector with on method jQuery?

I've created two of selection and check up with items was selected by using on jQuery method.

I have two of selector id (#idchief, #teller) and I will use $(document).on method to check up if an item was selected but I don't want to use document.on () twice. I want to check if on selection was select and process of this selection.

$(document).on('change','#idchief', function (event) {

    console.log($("#idchief"));
    var id = parseInt($("#idchief").val());

    for(var keys in cheifs) {
        var vals = cheifs[keys];
        if(parseInt(vals.id) === id){
            console.log(vals.id);
        }
    }
});

$(document).on('change','#teller', function (event) {

    var vals = null;
    var sel = $("#teller").val();
    for(var key in tellers) {
        vals = tellers[key];
            console.log(sel)
        if(vals.id == sel){

            $('input[name=amount]').val(vals.balance)
        }
    }
});

I have tried this

$(document).on('change','#teller,#idchief', function (event) {

   if($teller){
       //code here
   }if(#idchief)(
     ///code here
   )
});
like image 603
DMS-KH Avatar asked May 31 '26 11:05

DMS-KH


1 Answers

Use is()

$(document).on('change','#teller, #idchief', function (event) {
    if ($(this).is('#teller')) {
    // OR
    // $(this).attr('id') === 'teller'
    // OR
    // this.id === 'teller'
like image 93
Tushar Avatar answered Jun 03 '26 01:06

Tushar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!