Replacing onClick event for IE and Chrome

One strange difference in my opinion between Firefox and Internet Explorer and most strange of all also a difference to Google Chrome is that the onclick-event is not recnognized. Here is a simple example just to illustrate.

<select id=”category”>
<option value=”3″ onclick=”getCategories(3);”>ACategoryWithCategoryNumberThree</option>

This works fine in Firefox, i.e. the function ‘getCategories’ gets called when choosing an object in the select box. This does not work for the other browsers though, the calls are not made and there are even no errors raised.

The solution is to make the function call on the select-tag instead using the onchange-event referencing the value of the select tag (which will hold the value of the chosen option-tag),

<select id=”category” onchange=”getCategories(document.getElementById(‘category’).value);”>
<option value=”3″>ACategoryWithCategoryNumberThree</option>

This way it will work for all three browsers!


Browsershots – Testare un sito web su oltre 50 versioni di browser

Utile strumento per web developer che permette di visualizzare come appare il nostro sito in oltre 50 versioni di browser differenti.
Offre la possibilità di settare alcune impostazioni quali le dimensioni dello schermo, flash, js etc.

L’elaborazione impiega un po’ ma ne vale davvero la pena.

Check Browser Compatibility, Cross Platform Browser Test – Browsershots

Blogged with the Flock Browser