Cool tip to trigger a button on the web

I had a problem where I didn’t want to re-invent the wheel. The scenario was that an existing button on a form was calling an @Function which was passing a field from the existing form. like → @Command( [ToolsRunMacro]; RejectAgentName )

What I wanted to do was to use JavaScript to have the user to confirm that’s really what they wanted to do prior to blasting the request. Since JavaScript and @Functions can’t be combined in a single button, I adapted a trick from Urs Meli using one button to call another using JavaScript. I hid the @Function button and showed a new JS button. That way I didn’t have to re-code the existing button and re-engineer a whole collection of subforms, scriptlibraries, etc. in a complex web application.

The steps that you don’t want to overlook is to give the old, hidden button a name (“ID”) that you can reference and use a simple CSS command to make the button invisible on the browser. You cannot use a hide-when or the button will not be rendered into HTML. Go to the properties box for the button and set:

ID → Hidden_Reject (or whatever name is appropriate)

Style → display:none

– code for new button –

// – Confirm whether or not the user really wants to reject the request –

// 12/2006 dcj Rather than jumping through lots of hoops to save the document and force an

// agent to run, simply simulate a click of the existing button which calls the agent.

//

if ( confirm( “Are you sure you want to REJECT this access request?” ) )

{

var rejBut = document.getElementById( "Hidden_Reject" );

if ( rejBut )

{

	rejBut.click( );

}

else

{

	alert( ' this should never happen -- no rejBut ' );

}

}

else

{

window.status = 'no action taken';

}

You may be wondering why I did it this way. Mainly because of interactions with other agents, buttons, and design elements which I did not want to hunt down, change, and debug. I found this to be an easy way to achieve it with a limited amount of fuss. There’s more than one way to skin a cat.

tip from Urs Meli:

http://www-10.lotus.com/ldd/nd6forum.nsf/0/9f80f0d4f90dc4408525712a005024a5?Open

HTH,

Doug

Subject: cool tip to trigger a button on the web

You can also use onclick event of the button to run both @Formula and Javascript.

You put @Command( [ToolsRunMacro]; RejectAgentName ) as usually, then in “Other” field of the button’s HTML tab put following:

onclick=“if(confirmAction()) return true else return false”

confirmAction() function must return boolean value indicating user’s choice. If true was returned, the code continues to run and the original action (@Formula) is executed, otherwise the code is aborted before it triggers the @formula action.

/Andrei

http://dominounlimited.blogspot.com

Subject: RE: cool tip to trigger a button on the web

Even better. I’ll try it.