Message from JavaScript discussions

November 2020

— Can't call php a bad practice


Let's say I have 1 script yes thats called main.js and I include that file in each page. Let's say I have a button called id="loginButton" the page can find it on the login page but can't find it on the register page

— How do I only run that function on the login page

— Include both.. it's not about files


— There is no button called loginButton on the registerpage

— So it gives an error button can't be found

— Fix the code then

— Yeah how thats what i'm asking

— What is good practice to do that

— Put each function in its own file? Put a function directly in the script tags? Put a function in the external file and call it in the html file

Message permanent page

— I just wanna know how someone with experience should handle this