1

Thank you in advance.

I need to build a JS file that contains some useful functions and wich will be reused on my website.

Content of File 1: utils.js

function clearForm(form){
$(form).find('input:text, input:password, input:file, select, textarea').val('');
$(form).find('input:radio, input:checkbox')
    .removeAttr('checked').removeAttr('selected');
}

function anotherFunction(){
//
}

function anotherFunction1(){
//
}

and this is the file 2: control.js

function postRecovery(email) {
var retorno;

$.ajax({
    url: "/auth/doRecuperarSenha/",
    dataType: "json",
    contentType: "application/json;charset=utf-8",
    type: "POST",
    data: JSON.stringify(email),
    async: true,
    beforeSend: function () {
        NProgress.start();
    },
    success: function (dados) {
       retorno = dados;
    },
    error: function () {
        alert("Erro");
    },
    complete: function () {
**this.clearForm(*email*);**
        NProgress.done();
    }
});
NProgress.remove();
}

But this does not work.

Clarification

I've imported the utils.js file before the control.js file on my html structure

My code worked when i put the script on the same file.

Community
  • 1
  • 1
thau0x01
  • 877
  • 1
  • 7
  • 18
  • 3
    http://stackoverflow.com/questions/25962958/calling-a-javascript-function-in-another-js-file – Michael Jan 04 '17 at 18:54
  • I don't think you are calling your function correctly. Write a log statement in your function and check if it is even being called correctly. – Thomas Juranek Jan 04 '17 at 18:56

0 Answers0