3.0.0

Mouse events on clickable control image

I'm in the process of contemplating rewriting some JavaScript code I have into an AW format.

One of the things I want to do is handle mouse events on an image in an input field. I more or less have this working with the following code -
<html>
<head>
...
<style>
#myInput .aw-item-image {cursor:pointer; position:absolute; right:-5px; margin-top:-2px}
#myInput .aw-item-text {left: 1px; width:80px}
</style>
</head>
<body>
<script>
    var obj     = new AW.UI.Input
    obj.setId("myInput")
    obj.setControlText("Find")
    obj.setControlImage("search")
    var img     = obj.getContent("box/image")
    img.setEvent("onclick", function(event)
    {
        alert("Hello")
        event.cancelBubble = true
    })
    document.write(obj)
    /*
    img.onControlClicked = function(event)
    {
        alert("Hello")
    }
    */
</script>
</body>
</html>

While this works with the image setEvent() call, I can't seem to get it to work with the onControlClicked call.

Can anyone give me any pointers?
Anthony
December 10,
OK, I'm stumped. I can I use onControlClicked with an image on its own, but not on an image in an input control.
<script>
    var obj     = new AW.UI.Input
    obj.setId("myInput")
    obj.setControlText("Find")
    obj.setControlImage("search")
    var foo     = obj.getContent("box/image")
    foo.setEvent("onclick", function(event)
    {
        alert("Hello")
        event.cancelBubble = true
    })
    document.write(obj)

    var img     = new AW.UI.ImageText
    img.setControlImage("favorites")
    img.onControlClicked = function(event)
    {
        alert("Hello there")
    }
    document.write(img)
</script>

the setEvent() call works, so there's no overall issue with events on images in other controls.
Anthony
December 11,
Anthony,
Wich Browser?
I tested 'as is' and it worked fine in IE6 FF20011 & FF3.
tried on a clean html ?
Carlos
December 12,
Hi Carlos, yes, the above works but I'm trying to use onControlClicked() rather than setEvent() on an image inside an input widget and that doesn't work.

I suppose the best thing is to leave the image outside the input widget. Although that would result in pages with odd alignments with images on either the left or right side of an input.
Anthony
December 12,
It seems I've come across another bug with this. onControlClicked() (and probably the other control event functions) seem to attach to the object's ID. So having multiple objects with the same ID causes the last defined onControlClicked() function to fire. But in an odd way. It fires once on the first one in a group and twice on every subsequent one.
Anthony
December 21,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.