Click here to Skip to main content
14,391,415 members
Rate this:
Please Sign up or sign in to vote.
See more:

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:

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

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...
Updated 1-Nov-19 2:41am
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

As @RichardDeeming said, the js file did not load properly... a Ctrl+F5 to refresh solved the issue.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100