Am I doing something wrong here? I have two anonymous functions to validate two different forms on two different pages. They both work individually though when I try and put them in the same script.js folder only one works.
I have two different forms on two different pages, one function is for one page and the other function is for the other. I wanted to combine the JS in a script.js doc. It seems that whichever function is on top is the one that works. Not sure what the problem is
Well Your problem here might be that when the page loads, it reads the script. If it can’t find an element by the name in the first function then an error would result. Have you checked your browser for error messages? I bet it can’t find the onsubmit attribute of a ‘null’ object. And so it never gets to the second function. There for which ever function is on top will work on the right page, but neither will work on the wrong page.
If this is the case, you could try resolving this with an if statement to check it whether that element even exists before creating the function.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic.
*May or may not contain any actual "CSS" or "Tricks".