Hello,
I'm trying to find a way to identify a button which is pressed without using id, so far with no luck.
-- markup --
<button style:x="350px" style:y="100px" style:width="200px" style:height="100px" style:position="absolute" />
<button style:x="350px" style:y="300px" style:width="200px" style:height="100px" style:position="absolute" />
<button style:x="350px" style:y="500px" style:width="200px" style:height="100px" style:position="absolute" />
<button style:x="350px" style:y="700px" style:width="200px" style:height="100px" style:position="absolute" />
<button style:x="350px" style:y="900px" style:width="200px" style:height="100px" style:position="absolute" />
-- script --
addEventListener("doAction",onAction,false);
function onAction(evt)
{
//code to change the width of the button which was pressed
}
For instance, I would like to catch which button was pressed in the above code and change the size of that button from script.

identifying button from script
Chris D Jones
You need something like this in your markup:
and then in your doAction handler, you can use something like:
to set the width of the target element to 500 pixels.
Derek at Potters Clay
Lawrence 007
One way would be to use the XML DOM APIs to get the element's parent and then check which of the childNodes has the same attributes.
Note that you CANNOT use object identity (eg, "if (evt.target.parentNode.childNodes[0] == evt.target) {...}") because XML does not guarantee that nodes have the same identity; you need to check if the object is the same through some other mechanism. Usually, that would be through the id... so you would have to check x, y, width, height, etc. or whatever unique value you have. You might also be able to check if the state.actioned property was set, but that depends on timing.
Any reason why you DON'T want ids They make life easier.
L&#225;szl&#243; N&#225;n&#225;ssy
Thanks,
I'm working on something which has over 70 buttons, so giving them all an unique id, like 1, 2, 3, etc., takes some work. I thought it would be faster if I just could get the number of the #th button which was pressed.
shankar ramachandran
Yes the doAction was send from the markup (xpath), the script line was what I need. Is it also possible to know which button send the action, for instance the 4th button was pressed (without using id).