Onclick Javascript Does Not Work in Google Chrome and Firefox?

By | March 6, 2011

Onclick Javascript in Google Chrome and Firefox Does Not Work?If you have found that onclick event does not work on Google Chrome, Firefox and Safari web browsers, then here is quick way to fix it:

Replace onclick form id with its name

For example, let’s say you have the following:

id=”form1″ name=”checkform1″

Find JS event:


Replace with:


All set. It now works with all web browsers.

About (Author Profile)

Vygantas is a former web designer whose projects are used by companies such as AMD, NVIDIA and departed Westood Studios. Being passionate about software, Vygantas began his journalism career back in 2007 when he founded FavBrowser.com. Having said that, he is also an adrenaline junkie who enjoys good books, fitness activities and Forex trading.

Comments (2)

Trackback URL | Comments RSS Feed

  1. Lars Gunther says:

    Better yet, don’t use this pattern at all. There is an implicit eval when you set a string as an event handler. Also, this example does not seem to be unobtrusive.

    It seems that this is what you’re looking for (depending on the rest of the HTML):

    document.getElementById(“the_button”).onclick = function () {
    document.getElementsByName(“cSSid”).value = “”;

    Also note that IE in real standards mode will noot leak ids as global symbols in JavaScript. Thus the very first code does not work in any browser if you’re doing things right.

  2. Rudi Visser says:

    It’s always been document.name, not document.id..