3

In Dashcode you can set up a handler for a behavior in the inspector.

Here's a sample handler for a button click on a button I've named "mybutton1" in the Inspector:

function myGetButtonName(event)
{
    var e = event.target;
    alert(e.id);
}

The problem is, when the button is clicked and the alert comes up it says the ID of the button is "DC_img1" rather than "myButton1" (which is what shows in the inspector in the id field).

I guess I'm not accessing the correct id.

Does anyone know how to get the id that shows in the attributes tab of the inspector?

Thanks!

Robert
  • 21,110
  • 9
  • 55
  • 65
tonyopp
  • 171
  • 6
  • This isn't really a direct answer so I'll post it as a comment. You can use console.log(event) to see everything available for you to in the event. If you're not seeing your `HTMLButtonElement` anywhere, that means it's not sending the event. You could be getting this sort of response if you're using `` and the user clicks directly on the image. It will still depress the button, but the image sends the event. – Robert Sep 28 '10 at 00:23

1 Answers1

2

OK, it turns out that the "id" that you may set on the attributes tab of the Dashcode Inspector is the CSS id of the element. I didn't realize that before.

To get that info I used this:

var x=event.currentTarget;
alert(x.id);

I don't know if it's the best way, but it gave me the correct result for each of the images that I was clicking on. I'm now getting the CSS id in the alert.

tonyopp
  • 171
  • 6
  • `currentTarget` is fine in everything except IE. The approach in my answer will work in all browsers. – Tim Down Sep 28 '10 at 08:18
  • Tim, my project is an iPhone Web App. The approach you suggested does not seem to work in DashCode. Maybe you missed my response to your suggestion, but when I tried to use alert(this.id) the alert displayed "undefined" instead of any name. – tonyopp Sep 28 '10 at 11:01
  • 1
    In which case you don't need my answer at all. I know nothing about Dashcode, didn't take in the bit about assigning the event handler via the Inspector and answered as though it were a general web question. Sorry. – Tim Down Sep 28 '10 at 11:33
  • Tim, no need to apologize. I so appreciate the help! – tonyopp Sep 28 '10 at 13:18