Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  7] [ 1]  / answers: 1 / hits: 28463  / 6 Years ago, fri, december 14, 2018, 12:00:00

I was trying to make a list where the user can add his or her favorites. But then I got a maximum call stack size exceeded error.



What is that and how do I fix it?



I'd appreciate the help, thank youuu



Here are the codes that I used:



    <body onload=onload();>
<!--for everything in the navigation part including the add favorite bar-->
<div class=topnav>
<!--links to the other pages-->
<a class=active href=home.html>Home</a>
<a href=games.html>Games</a>
<a href=movies.html>Movies</a>
<a href=series.html>TV Series</a>
<a href=books.html>Books</a>

<!--for the add favorite button-->
<div class=addFave>
<!--the text bar-->
<input type=text name=enter class=enter value= id=added placeholder= Add Favorites/>
<!--the enter button-->
<input type=button value=Enter id = addIt OnClick=adding() />
<!--for the script of the add favorite bar to add its functions-->
<script type=text/javascript>
var faves = [];

var y = document.getElementById(added);
function adding() {
faves.push(y.value);
document.getElementById(faveLists).innerHTML = faves;
}
var input = document.getElementById(added);
input.addEventListener(keyup, function(event) {
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById(addIt).click();
}
});
</script>
</div>
</div>




<!--for the additional texts-->
<div class=list>
<!--where the user input in the add favorite bar will appear-->
<p id = faveLists></p>
</div>
</body>
</html>

More From » javascript

 Answers
57

The Maximum call stack size exceeded. appears when you enter something like an infinite loop of function!



Check a better example here



In your <body> you are typing: onload=onload(); and that's the reason of your problem because onload is calling itself, over and over. Try to remove it from your code, and the error will be disappeared.



Welcome to StackOverflow!


[#52922] Monday, December 10, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelyn

Total Points: 619
Total Questions: 102
Total Answers: 104

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;