slide 1 of 3
onClick Event Handler
As the name suggests, onClick is set into motion when a user clicks on something in particular on the webpage. For example, if there was a link on a website splash page and it contained a link to enter the site:
The onClick event handler would display a message box, with the message ‘Welcome!’ and move to the HTML page ‘firstpage.html’.
Although onClick is often used with text links, it is not restricted to them at all. It can be embedded in input objects, like buttons, or with form elements. Additionally, onClick can be used to call functions that are embedded in script blocks, thereby eliminating the need to create an entire block in the middle of an HTML tag.
slide 2 of 3
Why onClick doesn’t work in Firefox
Firefox also has trouble with the onClick event handler for various reasons, and each time the solution is entirely different. The interpretation is not always predictable, so the following is a list of common potential problems that may be causing the onClick handler to fail in Firefox:
When using the onClick event handler, it is always better to include a return statement. Sometimes, if the values of a function call are not what were expected, the onClick function will appear to fail if it does nothing. Therefore adding a return statement will act as an exception handler, in case of unexpected results.
In some cases, the problem may not be with the onClick event handler at all. If the href attribute is not defined correctly, all the actions of that anchor tag will potentially fail, including onClick. For instance, although the href attribute is a mandatory part of the anchor tag, developers may not want to use its functionality always. Therefore sometimes a null value is used. However, how the null value is specified is vital, as empty quotes are not accepted by Firefox. It would be best in these cases to use the hash symbol ‘#’.
slide 3 of 3