{"id":67133,"date":"2006-06-12T13:24:00","date_gmt":"2006-06-12T13:24:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/06\/12\/how-can-i-add-a-right-to-left-text-box-to-a-web-page\/"},"modified":"2006-06-12T13:24:00","modified_gmt":"2006-06-12T13:24:00","slug":"how-can-i-add-a-right-to-left-text-box-to-a-web-page","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-add-a-right-to-left-text-box-to-a-web-page\/","title":{"rendered":"How Can I Add a Right-to-Left Text Box to a Web Page?"},"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 add a right-to-left text box to a Web page?<BR><BR>&#8212; B<\/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, B. To begin with, we should note that we aren\u2019t entirely sure that we know what we\u2019re talking about here. (Good point: that\u2019s a disclaimer that <I>could<\/I> be added to all of our columns, couldn\u2019t it?) We are aware of languages &#8211; Arabic languages and Hebrew, for example &#8211; that are read from right-to-left; however, we aren\u2019t exactly proficient in any of those languages. (And, as our editor continually points out, we aren\u2019t all that good when it comes to English, either.)<\/P>\n<P>Nevertheless, we think (hope) that this is what you had in mind:<\/P><PRE class=\"codeSample\">&lt;SCRIPT LANGUAGE=&#8221;VBScript&#8221;&gt;\n    Sub TestSub\n        Msgbox ScriptArea.Value       \n    End Sub\n&lt;\/SCRIPT&gt;<\/p>\n<p>&lt;body&gt;\n    &lt;textarea name=&#8221;ScriptArea&#8221; rows=5 cols=70 dir=&#8221;rtl&#8221;&gt;&lt;\/textarea&gt;&lt;p&gt;\n    &lt;input id=runbutton  type=&#8221;button&#8221; value=&#8221;Run Script&#8221; onClick=&#8221;TestSub&#8221;&gt;\n&lt;\/body&gt;\n<\/PRE>\n<P>Believe it or not, this is even easier than it looks; after all, much of the code is there in order to: 1) create a button (which you might not need in your Web page or HTA), and 2) to add a subroutine that runs when the button is clicked. As it turns out, the part you <I>really<\/I> care about consists of nothing more than a single HTML tag:<\/P><PRE class=\"codeSample\">&lt;textarea name=&#8221;ScriptArea&#8221; rows=5 cols=70 dir=&#8221;rtl&#8221;&gt;&lt;\/textarea&gt;\n<\/PRE>\n<P>What we\u2019re doing here is adding a multi-line text box control (or a &lt;textarea&gt;) named ScriptArea; we\u2019re also sizing the text box so it displays 5 rows, with 70 columns per row. Nothing too fancy there. But take a look at this additional property assignment: <B>dir=&#8221;rtl&#8221;<\/B>. <I>That\u2019s<\/I> the cool part. The <B>dir<\/B> property determines the reading order of a text box. If dir is set to <I>rtl<\/I> then the reading order is right-to-left, which is what you were looking for. If dir is set to <I>ltr<\/I> (or if the dir property is omitted altogether) then the reading order is set to left-to-right. Believe it or not, that\u2019s all we have to do to create a right-to-left text box.<\/P>\n<P>Here\u2019s what the text box looks like when added to an HTA (HTML Application):<\/P><IMG border=\"0\" alt=\"Hey, Scripting Guy!\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/righttoleft.jpg\" width=\"400\" height=\"167\"> \n<P><BR>Not bad, if we do say so ourselves. (Or, if you\u2019re reading from right-to-left: dab toN.) Type the information into the text box and click the <B>Run Script<\/B> button; with any luck, a message box will appear echoing back the contents of the text box.<\/P>\n<P>Now, we know what you\u2019re thinking: yes, the text is right-justified and, yes, the periods are in an unusual place. However, the text doesn\u2019t actually <I>read<\/I> right-to-left. True: that\u2019s because we\u2019re typing in English, which uses the so-called Latin alphabet. Text will not be displayed right-to-left when using a Latin alphabet. But things will be very different if you type using Arabic, Farsi, Hebrew, or any other language that <I>does<\/I> read from right-to-left. (Try it and see.) <\/P>\n<TABLE id=\"EHE\" 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>. You say you don\u2019t have any idea what an HTA is, and you don\u2019t really understand what it means to add an HTML control? Then you need to check out the <A href=\"http:\/\/null\/technet\/scriptcenter\/hubs\/htas.mspx\"><B>HTA Developers Center<\/B><\/A> here in the Script Center.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Because we have some time to kill (no baseball game tonight), we thought we\u2019d toss in some bonus code, just for the heck of it. The following Web page\/HTA has <I>two<\/I> buttons on it: not only does it have the <B>Run Script<\/B> button but it also has a button labeled <B>Switch Direction<\/B>. When you click the <B>Switch Direction<\/B> button the following subroutine runs:<\/P><PRE class=\"codeSample\">Sub SwitchSub\n    If ScriptArea.dir = &#8220;ltr&#8221; Then\n        ScriptArea.dir = &#8220;rtl&#8221;  \n    Else\n        ScriptArea.dir = &#8220;ltr&#8221;\n    End If     \nEnd Sub\n<\/PRE>\n<P>As you can see, this subroutine checks the value of ScriptArea\u2019s dir property. If dir is equal to <I>ltr<\/I>, then the value is changed to <I>rtl<\/I>; if the value is <I>not<\/I> equal to <I>ltr<\/I> (meaning it must be equal to <I>rtl<\/I>) then the value is changed to <I>ltr<\/I>. To put all that in somewhat plainer English, the button simply toggles ScriptArea between right-to-left and left-to-right. Click the button once and the text box reading direction will be left-to-right; click it a second time, and the reading direction switches back to right-to-left. Etc. etc.<\/P>\n<P>Here\u2019s the complete code:<\/P><PRE class=\"codeSample\">&lt;SCRIPT LANGUAGE=&#8221;VBScript&#8221;&gt;\n    Sub TestSub\n        Msgbox ScriptArea.Value       \n    End Sub<\/p>\n<p>    Sub SwitchSub\n        If ScriptArea.dir = &#8220;ltr&#8221; Then\n           ScriptArea.dir = &#8220;rtl&#8221;  \n        Else\n           ScriptArea.dir = &#8220;ltr&#8221;\n        End If     \n    End Sub\n&lt;\/SCRIPT&gt;<\/p>\n<p>&lt;body&gt;\n    &lt;textarea name=&#8221;ScriptArea&#8221; rows=5 cols=70 dir=&#8221;rtl&#8221;&gt;&lt;\/textarea&gt;&lt;p&gt;\n    &lt;input id=runbutton  type=&#8221;button&#8221; value=&#8221;Run Script&#8221; onClick=&#8221;TestSub&#8221;&gt;\n    &lt;input id=switchbutton  type=&#8221;button&#8221; value=&#8221;Switch Direction&#8221; onClick=&#8221;SwitchSub&#8221;&gt;\n&lt;\/body&gt;\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I add a right-to-left text box to a Web page?&#8212; B Hey, B. To begin with, we should note that we aren\u2019t entirely sure that we know what we\u2019re talking about here. (Good point: that\u2019s a disclaimer that could be added to all of our columns, couldn\u2019t it?) We are [&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-67133","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 add a right-to-left text box to a Web page?&#8212; B Hey, B. To begin with, we should note that we aren\u2019t entirely sure that we know what we\u2019re talking about here. (Good point: that\u2019s a disclaimer that could be added to all of our columns, couldn\u2019t it?) We are [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67133","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=67133"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67133\/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=67133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}