Load selected JS depending on a checkbox on form

Forums General discussion Load selected JS depending on a checkbox on form

This topic contains 3 replies, has 2 voices, and was last updated by  Alexander Bautz 1 day, 14 hours ago.

  • Author
    Posts
  • #24837

    Eddie Pryce
    Participant

    Is it possible to load custom JS depending on on a checkbox being selected in a tab?
    I have some custom JS that works as a cascading dropdown but i need to add in some more code but i only want the new JS to load if i have checked a box and the old code to stop working

    • This topic was modified 2 days, 14 hours ago by  Eddie Pryce.
  • #24862

    Alexander Bautz
    Keymaster

    You should be able to do this by triggering a function either on page load (by checking the value in the checkbox) or by a rule triggering on the checkbox. What kind of code is it you want to cancel, and what is it you like to trigger?

    Alexander

  • #24866

    Eddie Pryce
    Participant
    
    
    jQuery(document).ready(function ()  
    {
         jQuery().SPServices.SPCascadeDropdowns(  
        {  
            relationshipList: "Contact",  
            relationshipListParentColumn: "Account",  
            relationshipListChildColumn: "Full_x0020_Name", 
            parentColumn: "Account",  
            childColumn: "Contact",  
            debug: true  
        });
        
        jQuery().SPServices.SPCascadeDropdowns(  
        {  
            relationshipList: "Machine",  
            relationshipListParentColumn: "Account",  
            relationshipListChildColumn: "Title", 
            parentColumn: "Account",  
            childColumn: "Machine",  
            debug: true  
        });
        
        jQuery().SPServices.SPCascadeDropdowns(  
        {  
            relationshipList: "Site",  
            relationshipListParentColumn: "Account",  
            relationshipListChildColumn: "Title", 
            parentColumn: "Account",  
            childColumn: "Site",  
            debug: true  
        });
        
        jQuery().SPServices.SPCascadeDropdowns(  
        {  
            relationshipList: "Area",  
            relationshipListParentColumn: "Account",  
            relationshipListChildColumn: "Title", 
            parentColumn: "Account",  
            childColumn: "Area",  
            debug: true  
        });
        
        jQuery().SPServices.SPCascadeDropdowns(  
        {  
            relationshipList: "Project",  
            relationshipListParentColumn: "Account",  
            relationshipListChildColumn: "Title", 
            parentColumn: "Account",  
            childColumn: "Project",  
            debug: true  
        });
        
        
        
    });

    This is my current code and i need this to stop and a similar set of code to load depending on a checkbox but there will be 3 check-boxes each to load different JS,

    im not really clued up on JS but i managed to get the above working the way i need it to

  • #24868

    Alexander Bautz
    Keymaster

    If the checkbox is checked when the page loads you can use something like this (expecting the checkbox to be boolean Yes/No):

    if(getFieldValue("NameOfYourCheckbox"){
       // Is checked - run your code here
    }else{
       // Not checked - run your alternative code here.
    }

    Alexander

You must be logged in to reply to this topic.