Click button from code?

Click button from code?

Post by amI » Tue, 23 Nov 2004 22:35:06


Can I write code (MS Script) from one button click handler to click another
button, or at least call its OnClick handler? I'm too lazy to factor out the
code into a shared function....
 
 
 

Click button from code?

Post by Greg Colli » Wed, 24 Nov 2004 11:50:56

Sure you can... just create a variable reference to the OnClick handler like so:

myBtnA = function btnA::OnClick(eventObj)
{
XDocument.UI.Alert("Whoohoo!");
}

function btnB::OnClick(eventObj)
{
myBtnA();
}

Notice the assignment of the function to the myBtnA variable?
Now you just call the function via the variable reference.

Cool, eh?


--
Greg Collins [InfoPath MVP]
Please visit: http://www.yqcomputer.com/




Can I write code (MS Script) from one button click handler to click another
button, or at least call its OnClick handler? I'm too lazy to factor out the
code into a shared function....

 
 
 

Click button from code?

Post by amI » Wed, 24 Nov 2004 17:15:03

You *have* to be joking :) Cool? Ugly, more like. Can I do the assignment
somehow not at the definition? Something more like:

var myBtnA = btnA::OnClick;

I feel I could live with that better... But perhaps not, since I couldn't
get to call the function that way in the first place...
 
 
 

Click button from code?

Post by Greg Colli » Thu, 25 Nov 2004 01:37:00

Sorry, that's how it works. JScript doesn't understand the "::" part on it's own. Since you don't like that answer, why not use the standard, perhaps more elegant, solution?

function myButtonProcess()
{
XDocument.UI.Alert("Whoohoo!");
}

function btnA::OnClick(eventObj)
{
myButtonProcess();
}

function btnB::OnClick(eventObj)
{
myButtonProcess();
}


--
Greg Collins [InfoPath MVP]
Please visit: http://www.yqcomputer.com/




You *have* to be joking :) Cool? Ugly, more like. Can I do the assignment
somehow not at the definition? Something more like:

var myBtnA = btnA::OnClick;

I feel I could live with that better... But perhaps not, since I couldn't
get to call the function that way in the first place...
 
 
 

Click button from code?

Post by amI » Thu, 25 Nov 2004 02:11:05

Thanks for the explanation. Yes, I thought JS didn't do "::".

Your latest solution is precisely what I knew, but am too lazy to do... :)
I'll have to choose between laziness and elegance!