Grow your CSS skills. Land your dream job.

Please Help! Only one Anonymous Functions works at a time.

  • # February 24, 2012 at 10:42 am

    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.



    # February 24, 2012 at 11:40 am

    To clarify, you have two forms on the same page and only one works? Or forms on separate pages validated in same script? Which of the two is working when combined?

    # February 24, 2012 at 11:52 am

    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

    Thanks

    # February 24, 2012 at 12:08 pm

    Have you tried making these named functions and then adding the onsubmit attribute to each form tag refrencing whichever function that form needs to call?

    # February 24, 2012 at 12:31 pm

    Yeah this will work, but I was trying to get it to where I don’t have to have any javascript in my HTML. My other websites are filled with this kind of stuff and I was trying to get it toned down.

    Thanks

    # February 24, 2012 at 3:43 pm

    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".