Sanjay Singh
Sanjay Singh

Reputation: 363

onClick event is not working in Safari but its working fine in IE/FF/Chrome/Opera browser

I am using JavaScript onClick event it's working good with IE/FF/Chrome browser but it not working for Safari browser.

The code which I am using are as follows:

heartSelectHandler = {
    clickCount : 0,
    action : function(select)
    {
        heartSelectHandler.clickCount++;
        if(heartSelectHandler.clickCount%2 == 0)
        {
            selectedValue = select.options[select.selectedIndex].value;
            heartSelectHandler.check(selectedValue);
        }
    },
    blur : function() // needed for proper behaviour
    {
        if(heartSelectHandler.clickCount%2 != 0)
        {
            heartSelectHandler.clickCount--;
        }
    },
    check : function(value)
    {
       alert('Changed! -> ' + value);
    }
}

<select onclick="javascript:heartSelectHandler.action(this);" onblur="javascript:heartSelectHandler.blur()" id="heart" data-role="none">
    <?php for ($i = 20; $i <= 150; $i++): ?>
    <option  value="<?php echo $i; ?>"><?php echo $i; ?></option>
    <?php endfor; ?>
</select>

Upvotes: 3

Views: 1707

Answers (1)

techfoobar
techfoobar

Reputation: 66663

Use onchange instead of onclick, as that will ensure that changes to selection purely via the keyboard will also trigger the event as expected (right?).

i.e. use:

onchange="javascript:heartSelectHandler.action(this);"

instead of:

onclick="javascript:heartSelectHandler.action(this);"

Upvotes: 1

Related Questions