Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm finishing the development of my time tracker php application.

After working a little with it (It's wonderful having something that suits perfectly your needs) i've noticed it would be a good thing having the possibility to set the number of lines to be shown in each page.

I've put a small editbox that in javascript it sets a cookie when enter key is pressed and then reloads the page to show the changes.

It works perfectly if I put the javascript code in the head of the php document.

But it doesn't work when I put the code inside a js file that is linked in the same head section of the same php document.

The function is this one:

JavaScript
function changeLiniesPerPagina(e)
{
  if(e.keyCode == 13)
  {
    document.cookie = "cookieName="+document.getElementById("lines").value+"; expires=Fri, 31 Dec 2049 12:00:00 UTC; path=/;";
    location.reload();
  }
}


If I use the "Inspect" option in the browser, I can see the message it appears when the function is located in an external js file is:

VM715 phpfilename.php:27 Uncaught ReferenceError: changeLiniesPerPagina is not defined
    at HTMLInputElement.onkeypress (VM715 phpfilename.php:27)
onkeypress @ VM715 phpfilename.php:27


Any idea?

Thank you very much!

What I have tried:

Checked the syntax, put the code snippet in different js files...
Posted
Updated 1-Nov-19 1:41am
Comments
Richard Deeming 1-Nov-19 7:24am    
Sounds like the external JS file hasn't been loaded correctly. Does it show up in the Debugger tab in your browser's developer tools, and does it have the correct content?
Joan M 1-Nov-19 7:41am    
AGAIN! Ctrl+F5 needed to refresh the contents... ^^¡

I think I'll never get used to do that... :D

Thank you Richard. I've noticed the function did not appeared into the js file... X|

1 solution

As @RichardDeeming said, the js file did not load properly... a Ctrl+F5 to refresh solved the issue.
 
Share this answer
 
Comments
phil.o 1-Nov-19 8:01am    
You may mark this as answered, so that it leaves the unanswered queue properly.
Thanks :)
Joan M 1-Nov-19 8:23am    
Done thx!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900