Page 1 of 1

Client Script Onload Event

Posted: Thu Feb 29, 2024 8:18 am
by lissa

hi can anyone help me,
My code successfully runs in client script->add/copy page->startup script.
but I put it on the edit page and I changed the event to onload and it didn't work.
I just changed the "change" event to "load"

this is the code:

$(document).ready(function(){
     $("#r_id_mob").hide();
     $("#r_km_st").hide();
     $("#r_km_en").hide();
     $("#r_km_tot").hide();
     $("#x_pak_mob").on("load", function() {
         var str = $("option:selected", this);
         if (this.value == "1") {
             $("#r_id_mob").hide();
             $("#r_km_st").hide();
             $("#r_km_en").hide();
             $("#r_km_tot").hide();
         } else {
             $("#r_id_mob").show();
             $("#r_km_st").show();
             $("#r_km_en").show();
             $("#r_km_tot").hide();
         }
     });
});

Re: Client Script Onload Edit Page

Posted: Thu Feb 29, 2024 9:07 am
by arbei
  1. Selection list are Select2 widget, there is no "load" event, see Events.
  2. Selection list options are loaded by Ajax, you need to wait until they are loaded, you may search "updatedone" in the docs or in this forum.
  3. You better use Client side events (for Add/Copy/Edit/Search).