Change order of running Javascript files

Asked

Viewed 212 times

1

I am developing a project that by clicking the button next to the ASP.NET Webforms application runs a dynamic code (this script is built on each page loading, Dynamic.JS - it is translated from C#programming blocks) and then in the same event you should call the relative functions in Validacoes.JS. The only problem is the execution order. The application calls Validacoes.JS before Dynamic.JS and for the application to behave as expected it needs Dynamic.JS to run first. How do I do that?

OBS: Calling one function within another would not be a viable solution for me. The name of the Function associated with the next button varies from page to page in the Dynamic.JS file

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Validacoes.JS ---> No momento é o primeiro a ser executado... deveria ser executado após o Dynamic.JS
// no ProximoButton esse evento verificacaoProximo está no onclick!


function verificacaoProximo() {
    if (retorno == "avanca") {
        if ($("#HiddenFielPodeAvancarTela").val().toString() == "0") { // PodeAvancar NAO
            if ($("#HiddenFielPodeAvancarTelaFlag").val().toString() == "1")
                retorno = "avanca";
            else
                retorno = "naoavanca";
        }
        else { // PodeAvancar SIM
            if ($("#HiddenFielPodeAvancarTelaFlag").val().toString() == "1")
                retorno = "avanca";
            else
                retorno = "naoavanca";
        }
    }
    return retorno;
}




//Dynamic.JS
$(document).ready(function () {

// HiddenField
if (!document.getElementById("hfcerto") ) {
var input792 = document.createElement("input");
input792.setAttribute("type","hidden");
input792.setAttribute("name", "hfcerto");
input792.setAttribute("value", "0");
input792.setAttribute("id", "hfcerto");
document.getElementById("hfs").appendChild(input792);
}

// HiddenField
if (!document.getElementById("hferro") ) {
var input121 = document.createElement("input");
input121.setAttribute("type","hidden");
input121.setAttribute("name", "hferro");
input121.setAttribute("value", "0");
input121.setAttribute("id", "hferro");
document.getElementById("hfs").appendChild(input121);
}



$("#ProximoButton892").click(function(){
    prox_click();
});

});



function prox_click(){
if((document.getElementById("hfcerto").getAttribute("value")=="8")&&(document.getElementById("hferro").getAttribute("value")=="0")){
document.getElementById("ImageButton1").src = document.getElementById("ImageButton2").src;
}
else if((document.getElementById("hfcerto").getAttribute("value")=="5")&&(document.getElementById("hferro").getAttribute("value")=="0")){
document.getElementById("ImageButton1").src = document.getElementById("ImageButton2").src;
}
else {
document.getElementById("ImageButton1").src = document.getElementById("PictureBoxProp891").src;

var valorHF = document.getElementById("HiddenFielQtdExercErrados").getAttribute("value");
document.getElementById("HiddenFielQtdExercErrados").setAttribute("value", parseInt(document.getElementById("HiddenFielQtdExercErrados").getAttribute("value")) + 1);
}
return false;
}
  • Could you publish your code? It would be easier to help like this. (;

  • Would it help? Remembering that it is dynamic! Each screen features different codes...

  • Published code @Felipeavelar

1 answer

1

I’ll demonstrate by analogy to a simple problem, and see if you can solve your problem with it.

jQuery has a graphical interface API, and it only works if the core jQuery is already loaded, so when calling the interface, first you call the core, encoding it would be something like

<script src="../js/js_1.9/jquery-1.8.2.js" type="text/javascript"></script> // Primeiro esse
<script src="../js/js_1.9/jquery-ui-1.9.1.custom.min.js?v=01" type="text/javascript"></script> // depois este
  • Document. Ready is read in the order in which the script is declared. This worked. But at the time I need it to perform the functions it does not follow the statement order....

  • Comments on each line of your code the order that is being executed so that I can better understand your case

Browser other questions tagged

You are not signed in. Login or sign up in order to post.