:: Forum >>

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
Wednesday, December 10, 2008
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
Thursday, December 11, 2008
Anthony,
Wich Browser?
I tested 'as is' and it worked fine in IE6 FF20011 & FF3.
tried on a clean html ?
Carlos
Friday, December 12, 2008
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
Friday, December 12, 2008
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
Sunday, December 21, 2008

This topic is archived.


Back to support forum

Forum search