Javascript does not load all functions

-2

Have one (one | one) (great | great) (day | late | night)!

Well then!

By inserting many functions into a <script type="text/javascript"></script> my code will not execute all of them! The browser console does not show any errors, and it performs them normally if I call them from the console, but if I call them by code, the script does not execute them, nor does it show this error below : function call is undefined. So I created an external JS file thinking that it could be the amount of functions (around 20 functions for example) but it did not work! I researched then. I found on a certain site somewhere, I forgot what it was, that suggested adding the language="javascript" attribute: <script type="text/javascript" language="javascript">/*Código aqui*/</script> He advanced : D ... for a short time. : / When adding some more functions, the code does not execute anymore. But if I call them like this in the address bar: javascript: FunctionName () ; or so on the console: FunctionName () It works normally. To not open another duplicate question I've seen here in stackoverflow similar questions. The problem with these is that people place functions within other functions, so they do not become global; Which is not my case. What could it be? Code address: link

To test, click on the year 2016.

    
asked by anonymous 19.06.2018 / 15:10

2 answers

1

var Problem = 'Solved';

Thank God, I did it! The problem, or rather, the issue is not "Javascript does not load all the functions". Well, I'll try to be clear!

I've created an app (calendar). and it appears in three menus:

  • List of years;
  • List of Months;
  • Month edit menu;

Inthemontheditingmenuyouareinformedifthismonththecontributorwillpayinthenormal/promotionalvalue.

IcreatedasubmenunamedMANAGEintheMonthListmenu:

Nottobeonebyoneediting.theteammemberselectseachmonthbyclickingoneachmonth,thus,opensthismenutodelete;settheselectedmonthsaspromotionalvalueornormalvalue.

WhathappenedinmyproblemisthatthefunctionIcreatednamedOpenOptionMes(formerly,whenpostingthisquestioninthis"forum", it was called OpenMenOption ) was called when the page was loaded. The problem is that the yearX month lists are only created when the member double-clicks on the year they want to edit. So the script will create the lists and write them all in html. This means that the OpenOptionMes function at the time it was called did not find the months (which did not yet exist in the HTML) to apply the addEventListener() event and then it was invalidated.

# SOLUTION

So simple this solution did not even need a topic. But how can someone have problems like mine; so come on. It's just a matter of logic.

Just apply the event, for example: document.addEventListener('click',abrirOptionMes) in the same function that inserts the list of months after the month has been added.

Illustrative example:

function insereMes(){
this.addMes=function(){
var minhaLi,htmlOuter='';
for(var i=0;i<=12;i++){
/*Gera em javascript os elementos <li>*/
var minhaLi=[],htmlOuter='';
minhaLi[i]=document.createElement("li");
minhaLi[i].innerText='01';
htmlOuter+=minhaLi[0].outerHTML
}
/*Insere todas as LI's e depois cria o evento addEventListener:*/
$('body > div#exemplo > ul').html(htmlOuter);document.addEventListener('click',abrirOptionMes)
}
}
    
20.06.2018 / 16:18
0

In my browser your script has a strange encoding, the name of a function is function modMesesOpção , try changing the encoding and see if it returns something different.

    
19.06.2018 / 18:08