{"id":69303,"date":"2005-07-27T18:30:00","date_gmt":"2005-07-27T18:30:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/07\/27\/how-can-i-include-multiple-subroutines-in-a-single-onclick-parameter-in-a-hta\/"},"modified":"2005-07-27T18:30:00","modified_gmt":"2005-07-27T18:30:00","slug":"how-can-i-include-multiple-subroutines-in-a-single-onclick-parameter-in-a-hta","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-include-multiple-subroutines-in-a-single-onclick-parameter-in-a-hta\/","title":{"rendered":"How Can I Include Multiple Subroutines in a Single onClick Parameter in a HTA?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! In your HTA examples, you show us how you can click a button and cause a single subroutine to run. How can I add two or more subroutines to the onClick parameter for a button?<BR><BR>&#8212; FM<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, FM. You know, there\u2019s an interesting branch of cognitive psychology known as problem <I>finding<\/I>; the idea is that your ability to answer a question often hinges on how you ask the question in the first place. For example, you &#8211; and several others &#8211; want to know how to specify multiple subroutines in the onClick parameter of a button. We\u2019ve seen people try several variations like this:<\/P><PRE class=\"codeSample\">&lt;input type=&#8221;button&#8221; value=&#8221;Run Button&#8221; onClick=&#8221;Script_1; Script_2; Script_3&#8243;&gt;\n<\/PRE>\n<P>As you\u2019ve discovered, that doesn\u2019t work.<\/P>\n<P>So let\u2019s put our problem-finding skills to the test and see if we can rephrase this question. (Typically the Scripting Guys don\u2019t need to find problems; problems have a way of finding <I>us<\/I>.) Here\u2019s the crux of the matter: do we really want to add multiple subroutines to the onClick parameter, or do we just want multiple subroutines to run any time we click the button?<\/P>\n<P>If it\u2019s the latter, then we have an answer for you:<\/P><PRE class=\"codeSample\">&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Multiple Subroutines&lt;\/title&gt;<\/p>\n<p>&lt;HTA:APPLICATION \n     ID=&#8221;objHTAHelpomatic&#8221;\n     APPLICATIONNAME=&#8221;MultipleSubroutines&#8221;\n     SCROLL=&#8221;yes&#8221;\n     SINGLEINSTANCE=&#8221;yes&#8221;\n     WINDOWSTATE=&#8221;maximize&#8221;\n&gt;\n&lt;\/head&gt;<\/p>\n<p>&lt;SCRIPT Language=&#8221;VBScript&#8221;&gt;<\/p>\n<p>Sub RunScripts\n    Script_1\n    Script_2\n    Script_3\nEnd Sub<\/p>\n<p>Sub Script_1\n    Msgbox &#8220;This is subroutine 1.&#8221;\nEnd Sub<\/p>\n<p>Sub Script_2\n    Msgbox &#8220;This is subroutine 2.&#8221;\nEnd Sub<\/p>\n<p>Sub Script_3\n    Msgbox &#8220;This is subroutine 3.&#8221;\nEnd Sub<\/p>\n<p>&lt;\/SCRIPT&gt;<\/p>\n<p>&lt;body&gt;\n    &lt;input type=&#8221;button&#8221; value=&#8221;Run Button&#8221; onClick=&#8221;RunScripts&#8221;&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/PRE>\n<TABLE id=\"EFD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. The preceding code is designed to be run from an <A href=\"http:\/\/null\/technet\/scriptcenter\/hubs\/htas.mspx\"><B>HTA, an HTML Application<\/B><\/A>. If you want to test the code, just copy the script, paste it into Notepad or some other text editor, and save the file using a .HTA file extension.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>If you glance through the code you might notice the HTML tag for the button:<\/P><PRE class=\"codeSample\">&lt;input type=&#8221;button&#8221; value=&#8221;Run Button&#8221; onClick=&#8221;RunScripts&#8221;&gt;\n<\/PRE>\n<P>As you can see, we specify only a single subroutine (RunScripts) in the onClick parameter. Ah, but take a look at the code for the subroutine RunScripts:<\/P><PRE class=\"codeSample\">Sub RunScripts\n    Script_1\n    Script_2\n    Script_3\nEnd Sub\n<\/PRE>\n<P>There\u2019s your answer right there. All we do inside this subroutine is call three other subroutines: Script_1, Script_2, and Script_3. That\u2019s how we can run multiple subroutines from a single button click: we don\u2019t put all those subroutines into the onClick parameter, we put them all into the single subroutine called by onClick.<\/P>\n<P>In other words, problem-finding &#8211; and cognitive psychology &#8211; to the rescue. And to think people told us that graduate school was a huge waste of time and money: at least we got a <I>Hey, Scripting Guy!<\/I> column out of it!<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! In your HTA examples, you show us how you can click a button and cause a single subroutine to run. How can I add two or more subroutines to the onClick parameter for a button?&#8212; FM Hey, FM. You know, there\u2019s an interesting branch of cognitive psychology known as problem finding; the [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3,4,5,30],"class_list":["post-69303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-web-pages-and-htas"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! In your HTA examples, you show us how you can click a button and cause a single subroutine to run. How can I add two or more subroutines to the onClick parameter for a button?&#8212; FM Hey, FM. You know, there\u2019s an interesting branch of cognitive psychology known as problem finding; the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=69303"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69303\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=69303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}