Assign onclick event dynamically

I have a JS function that assigns onclick to an HTML IMG tag. It saw some information about IE Vs. non-IE implementation.

My code (else part) doesn't work. So FF/Safari/Chrome don't work. Please share your ideas if you can.


    if (BrowserDetect != null && BrowserDetect.browser.indexOf("Explorer") != -1) {
        $get('imgPrevAlert').onclick = 'jsFnPrevAlert(\'' + aStrUserDBID + '\',\'' + aStrUsername + '\');';
        $get('imgNextAlert').onclick = 'jsFnNextAlert(\'' + aStrUserDBID + '\',\'' + aStrUsername + '\');';
    else {
        //None of the following two approaches work        
        //$get('imgPrevAlert').onclick = function() { jsFnPrevAlert(aStrUserDBID, aStrUsername); };
        //$get('imgNextAlert').onclick = function() { jsFnNextAlert(aStrUserDBID, aStrUsername); };
        $get('imgPrevAlert').onclick = new Function("jsFnPrevAlert('" + aStrUserDBID + "','" + aStrUsername + "');");
        $get('imgNextAlert').onclick = new Function("jsFnNextAlert('" + aStrUserDBID + "','" + aStrUsername + "');");    
5/4/2009 9:48:16 PM 24353 articles. 1 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 31

this is worth a look


Liam Mcmullen
5/4/2009 10:00:10 PM

These are not server-side image controls. They are plain HTML img tags. So the link you suggested won't help. Thanks anyway.

5/4/2009 10:16:18 PM

if you add the runat = "server "  and give the HTML  img tage an ID then you can access them from the code behind.

with somthing like


img1.Attributes.Add("onmouseover", "javascriptFunctionName();")


hope this  helps.



Liam Mcmullen
5/4/2009 10:21:41 PM

I can't make them server-side.

5/4/2009 10:36:01 PM
5/4/2009 10:53:58 PM

Web resources about - Assign onclick event dynamically -

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ... launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...

A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97% Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/12/2015 12:32:35 PM