locked
onclick event not working in multiple browsers RRS feed

  • Question

  • Hi All,

                Am having a Lookup when i click on that i need to show an alert. Please find the below code its working fine in IE not in CHROME AND FIREFOX. Please Guide me to 

       var control = document.getElementById("new_technologyid");
        if (control) {
            control.attachEvent("onclick", control_clicked);
        }

        function control_clicked() {
            alert('If multiple horizontals, Please select the largest revenue horizontal first');
        }

    Monday, March 17, 2014 7:38 AM

All replies

  • Be aware that the code:

       control.attachEvent("onclick", control_clicked);

    Is not supported by Firefox and Chrome.

    in order for this to work you need to replace it by  "addEventListener"

    And on your code you probably will need to make a browser validation, something like this:

     if (navigator.userAgent.indexOf('Firefox') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox') + 8)) >= 3.6){//Firefox
     //Allow
     }else if (navigator.userAgent.indexOf('Chrome') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Chrome') + 7).split(' ')[0]) >= 15){//Chrome
     //Allow
     }else if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Version') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Version') + 8).split(' ')[0]) >= 5){//Safari
     //Allow
     }else{
     // Block
     }

    Monday, March 17, 2014 9:16 AM