{"id":69633,"date":"2005-06-09T11:10:00","date_gmt":"2005-06-09T11:10:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/06\/09\/how-can-i-clear-a-text-box-in-an-hta\/"},"modified":"2005-06-09T11:10:00","modified_gmt":"2005-06-09T11:10:00","slug":"how-can-i-clear-a-text-box-in-an-hta","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-clear-a-text-box-in-an-hta\/","title":{"rendered":"How Can I Clear a Text Box in an 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! How can I clear a text box in an HTA?<BR><BR>&#8212; CB<\/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, CB. You know, it\u2019s been awhile since we\u2019ve answered a question about HTAs (HTML Applications). And we could probably get away with that except for the fact that a month or so ago we debuted the <A href=\"http:\/\/null\/technet\/scriptcenter\/hubs\/htas.mspx\"><B>HTA Developer\u2019s Center<\/B><\/A>, something which implied that we were going to try and do a better job of supporting people interested in writing HTAs. So <I>have<\/I> we done a better job of supporting people interested in writing HTAs? You know, that\u2019s a very important question. Too bad we don\u2019t have time to answer it\u2026.<\/P>\n<P>But look on the bright side: today, at least, we <I>are<\/I> supporting people interested in writing HTAs. So let\u2019s see if we can figure out how to programmatically clear a text box.<\/P>\n<P>We\u2019re assuming you have an HTA vaguely similar to this; in other words, you have a text box where users can enter data. You also have a button that makes it very easy for users to erase that data and start over again; all they have to do is click the <B>Clear Text<\/B> button and any text in the text box will be erased. In our simplified version the HTA looks like this:<\/P><IMG border=\"0\" alt=\"HTA\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/cleartextbox.jpg\" width=\"312\" height=\"188\"> \n<P><BR>There\u2019s just one catch: how do we erase the text any time a user clicks the button? <\/P>\n<P>Believe it or not that\u2019s one of the easiest things you\u2019ll ever do in scripting. In HTML each text box has a property named <B>Value<\/B>, which represents whatever happens to be in the text box at the moment. For example, in our sample HTA the textbox has the value <I>This text box has text in it<\/I>. If we want to get rid of that text all we have to do is set the Value property to nothing. Assuming our text box is named MyTextBox this line of code will do the trick:<\/P><PRE class=\"codeSample\">MyTextBox.Value = &#8220;&#8221;\n<\/PRE>\n<P>That\u2019s all there is to it. If we wanted to change the text so it read \u201cPlease enter your name here:\u201d we\u2019d use this line of code:<\/P><PRE class=\"codeSample\">MyTextBox.Value = &#8220;Please enter your name here:&#8221;\n<\/PRE>\n<P>If you\u2019d like to try this out on your own here\u2019s the complete code for our sample HTA. Just copy the following into Notepad and then save the file with a .hta file extension:<\/P><PRE class=\"codeSample\">&lt;head&gt;\n&lt;title&gt;HTA Test&lt;\/title&gt;\n&lt;HTA:APPLICATION \n     APPLICATIONNAME=&#8221;HTA Test&#8221;\n     SCROLL=&#8221;yes&#8221;\n     SINGLEINSTANCE=&#8221;yes&#8221;\n&gt;\n&lt;\/head&gt;<\/p>\n<p>&lt;script language=&#8221;VBScript&#8221;&gt;\n    Sub ClearText\n       MyTextBox.Value = &#8220;&#8221; \n    End Sub\n&lt;\/script&gt;<\/p>\n<p>&lt;body&gt;\n    &lt;input type=&#8221;text&#8221; name=&#8221;MyTextBox&#8221; size=40 value=&#8221;This text box has text in it&#8221;&gt;&lt;p&gt;\n    &lt;input type=&#8221;button&#8221; value=&#8221;Clear Text&#8221; name=&#8221;run_button&#8221; onClick=&#8221;ClearText&#8221;&gt;\n&lt;\/body&gt;\n<\/PRE>\n<P>And before you ask, yes, this same approach can also be used to clear any text typed into a text area. That\u2019s right, with today\u2019s Internet special you get <I>two<\/I> questions answered for the price of one. Let\u2019s see any other daily scripting-related question-and-answer column found on the Internet beat <I>that<\/I> deal.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I clear a text box in an HTA?&#8212; CB Hey, CB. You know, it\u2019s been awhile since we\u2019ve answered a question about HTAs (HTML Applications). And we could probably get away with that except for the fact that a month or so ago we debuted the HTA Developer\u2019s Center, something [&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-69633","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! How can I clear a text box in an HTA?&#8212; CB Hey, CB. You know, it\u2019s been awhile since we\u2019ve answered a question about HTAs (HTML Applications). And we could probably get away with that except for the fact that a month or so ago we debuted the HTA Developer\u2019s Center, something [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69633","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=69633"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69633\/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=69633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}