Sunday, July 8, 2012

Button Confirmation Message

This is a quick way to add a javascript confirmation message to a button.

Firstly make sure that your button template uses #BUTTON_ATTRIBUTES# substitution string (note  #BUTTON_ID# doesn't seem to work as expected here). Add a button id to the Attributes field, or otherwise ensure you can identify it with a jQuery selector.


Then in Post Element Text place some jQuery to extend the click event...


I figure this method should be pretty robust. Here's the code for copy/pastability:

<script>
var btnClick = $('#PX_MYBUTTON').attr('onclick');
$('#PX_MYBUTTON')
 .removeAttr('onclick')
 .unbind('click')
 .click(function(e){
  if (confirm('Confirm message.')) btnClick(e);
 });
</script>