Javascript does not load all functions

Asked

Viewed 873 times

-2

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

All right!

When inserting many functions in a <script type="text/javascript"></script> My code is not running all of them! The browser console does not show no errors, and runs them normally if I call them by the console, however, if I call them by code, the script does not execute them, nor even shows this error below: Function call is Undefined. So I created an external JS file thinking it could be the number of functions (around 20 functions for example) but nothing helped! I researched then. I found in a certain site around, I forgot what it was, that suggested to add in the attribute language="javascript": <script type="text/javascript" language="javascript">/*Código aqui*/</script> Said :D...for a short time. :/ When adding a few more functions, the code no longer performs. But if I call them that in the address bar: javascript:nameFunction(); or so on the console: nameFunction() it works normally. Not to open another duplicate question I’ve seen here in stackoverflow similar questions. The problem with these is that people put functions within other functions, so they don’t go global; that’s not my case. What could it be? Code address: http://leonardolima.epizy.com/calendario.php

To test, click on the year 2016.

  • Place your code here or make it available in any way.

  • I added the code url

  • Press the F12 key to open the Console and see if an error appears while loading your script.

2 answers

1


var Problem = 'Solved';

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

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

  • Birthday list;
  • List of Months;
  • Menu of edition of the month;

Lista de Anos Lista de Meses Menu de edição de mês

In the month edition menu it is informed if in this month the contributor will pay in the normal value/ promotional.

I created in the Months List menu a submenu called MANAGE:

Mês com o

So you don’t get one by one editing. the team member selects every month by clicking each month, thus opens this menu to delete; set as promotional value or normal value the selected months.

What happened in my problem is that the function I created named open up(in the past, when posting this question in this "forum", it was called open) was called when the page was loaded. The problem is that the month lists of the anoX are created only when the member clicks twice in the year he wants to edit. Thus, the script will create the lists and write all of them in html. This means that the function open up at the time it was called did not find the months, (which did not yet exist in HTML) to apply the event addEventListener() and then she was invalidated.

#SOLUTION

So simple this solution that it didn’t even need a topic. But as someone can have problems like mine; so here we go. 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 adding the months.

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)
}
}

0

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

  • Regarding this encoding problem: the code is written in UTF-8 and is still seen as unknown by the server Infinity Free. But that was not the problem. It has already been solved.

Browser other questions tagged

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