If you tried with little success to attach some javascript code to an Apex item button (not a region button, that's a piece of cake...) , it may console you to know that i have been in the same situation for some time.
I wanted to catch button clicks and display one of those classic, annoying pop up messages asking "do you
really really really want to delete this stuff?"
With a normal region button it's pretty easy, although it's not so straightforward.
You need to go to the button property called
optional URL redirect and pick the value
URL and put something like:
javascript:confirmDelete('Press OK to delete the selected rows',
'MULTI_ROW_DELETE');in the
URL target attribute.
Unfortunately
item buttons don't come with the same feature, so one starts wondering about some fancy way of hacking the system.
Luckily enough, if you opt for a template based button, there is a property called
Attributes where apparently you can put your stuff.
But this is just the half of the moon.
Because the button template you are using might not include a #BUTTON_ATTRIBUTES# substitution string in its definition (as suggested in Apex on-line help), so, whatever you put there, it won't work because it will be left out.
So, to get to the other side of the moon, you need to customize the template button, or better, to make a copy of an existing one and customize the duplicate, just in case you don't want to mess up the entire application.
Here is how i did it:
first i picked the
Button, Alternative 2 template (may be it doesn't exist such template in the theme you're currently using, so pick a different one) and copied it, using the built-in copy feature.
With much fantasy i renamed it to
Button, Alternative 2, Custom.
Here is the template
before i started hacking it:
<table class="t1ButtonAlternative2"
cellspacing="0" cellpadding="0"
border="0" summary="">
<tr>
<td class="t1L">
<a href="#LINK#">
<img src="#IMAGE_PREFIX#themes/theme_1/button_alt2_left.gif"
alt="" width="11" height="20" />
</a>
</td>
<td class="t1C">
<a href="#LINK#">#LABEL#</a>
</td>
<td class="t1R">
<a href="#LINK#">
<img src="#IMAGE_PREFIX#themes/theme_1/button_alt2_right.gif"
width="11" height="20" alt="" />
</a>
</td>
</tr>
</table>
As you see there was no trace of the #BUTTON_ATTRIBUTES# mentioned above, so i changed it as follows:
<table class="t1ButtonAlternative2"
cellspacing="0" cellpadding="0"
border="0" summary="">
<tr>
<td class="t1L">
<a href="#BUTTON_ATTRIBUTES#">
<img src="#IMAGE_PREFIX#themes/theme_1/button_alt2_left.gif"
alt="" width="11" height="20" />
</a>
</td>
<td class="t1C">
<a href="#BUTTON_ATTRIBUTES#">#LABEL#</a>
</td>
<td class="t1R">
<a href="#BUTTON_ATTRIBUTES#">
<img src="#IMAGE_PREFIX#themes/theme_1/button_alt2_right.gif"
width="11" height="20" alt="" />
</a>
</td>
</tr>
</table>
This template will work well provided you perform the following settings in the button definition:
Happy scripting.