Click button from code?

J

jb

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....
 
J

jb

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...
 
J

jb

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!

Greg Collins said:
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.InfoPathDev.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...

Greg Collins said:
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.InfoPathDev.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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top