I can not use functions, variables from another file js

0

Hello everyone I need your help I'm creating a form validation in jquery for this I'm doing it in two js files:

  • validation-form.js
  • ajax.js
  • The first with a function to validate and the second with a function to send the form data using ajax. The problem is that I want to use the function of the ajax.js file inside the validation-form.js file

    //ajax.js
    $(document).ready(function() {
    function SendForm(){
    //Codigo
    })
    

    / ********************** /

    //validacion-form.js
            $(document).ready(function() {
            function Validar(){
            //Codigo
            SendForm();//Aqui llamo la funcion dentro de validacion-form.js
            })
    

    I get the following error:

      

    Uncaught ReferenceError: SendForm is not defined

    I think it might be for $ (document) .ready (function () {}) but if I delete this I can not use some of the functions of my code. I need your help please.

        
    asked by Arellano Cornejo Daniel 25.02.2018 в 18:18
    source

    1 answer

    0

    Your SendForm function is not global, it is in a scope not accessible by any other function that is not minimal in the same scope as your function, therefore your other file in your Validate function will not find it.

    Solution?

    Declare the functions you need between files in a global way (outside the jQuery ready).

        
    answered by 25.02.2018 / 19:39
    source