• Calling functions in one JS file from another JS file

    Arden Member

    I created a file called General.js and one called AddAdmin.js

    AddAdmin needs to use the functions in General. Using google, I got the codes below, which do not work.

    General has:

    function lengthCheck(param1,param2,param3){}
    function presenceCheck(param4,param5){}
    function typeCheck(param6,param7, param8){}
    

    AddAdmin has

    function adminValidation(){
    
    lengthCheck(arg,arg,arg){}
    presenceCheck(arg,arg){}
    typeCheck(arg,arg, arg){}
    
    lengthCheck(arg,arg,arg){}
    presenceCheck(arg,arg){}
    typeCheck(arg,arg, arg){}
    
    lengthCheck(arg,arg,arg){}
    presenceCheck(arg,arg){}
    typeCheck(arg,arg, arg){}
    
    }
    

    arg has different values but to save time, in this post, i wrote the same thing (arg)
    I’m doing this so as to reduce the amount of JS in my .html file [ the codes work using onclick]

  • Adelaid Member

    Include the scripts in the order they are needed, so general and then addadmin.

    
    

    The later scripts can then access the earlier included scripts using regular function calls.

    Your snippet has AdAdmin redeclare the functions from General, not calling them btw.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish