<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Subhajit Saha</title>
    <description>The latest articles on DEV Community by Subhajit Saha (@subhajit_saha).</description>
    <link>https://dev.to/subhajit_saha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F270772%2F243f6362-3705-4562-a5da-410dee09e505.jpg</url>
      <title>DEV Community: Subhajit Saha</title>
      <link>https://dev.to/subhajit_saha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/subhajit_saha"/>
    <language>en</language>
    <item>
      <title>Introduction to JavaScript Series - #1 - Form with String Object</title>
      <dc:creator>Subhajit Saha</dc:creator>
      <pubDate>Sat, 23 Jan 2021 10:21:31 +0000</pubDate>
      <link>https://dev.to/subhajit_saha/introduction-to-javascript-series-1-form-with-string-object-3emm</link>
      <guid>https://dev.to/subhajit_saha/introduction-to-javascript-series-1-form-with-string-object-3emm</guid>
      <description>&lt;p&gt;Let's design a &lt;strong&gt;text editor&lt;/strong&gt; where you can input your text and get a result of the number of words in your text using HTML, JavaScript and CSS styling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--Code Segment1--&amp;gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;Form with String object&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this portion of code we are giving a title to our webpage which is &lt;em&gt;"Form with String object"&lt;/em&gt; inside the &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; tag, which is embedded inside the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--Code Segment1--&amp;gt;
&amp;lt;body style="background-color:orange"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the &lt;code&gt;style&lt;/code&gt; attribute of the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag, we are specifying the CSS styling of &lt;code&gt;background-color&lt;/code&gt; to &lt;code&gt;orange&lt;/code&gt;. This will set the background color of the webpage to orange.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--Code Segment3--&amp;gt;
&amp;lt;h3&amp;gt;Enter your text in the given text area&amp;lt;/h3&amp;gt;
&amp;lt;form name="wordcount"&amp;gt;
  &amp;lt;textarea name="wordcount2" rows="12" cols="38" wrap="virtual" style="color:white;background-color:black;font-size:20px;"&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;
  &amp;lt;input type="button" value="Calculate Words" onClick="Countit()"&amp;gt;
  &amp;lt;input type="text" name="wordcount3" size="20"&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code segment, we are giving a name to the &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; which is &lt;code&gt;wordcount&lt;/code&gt; and specifying the text area, in which the user will input the text. The text area name is given as &lt;code&gt;wordcount2&lt;/code&gt;, which will be helpful for JavaScript to access the specific document elements. We are prescribing this specific styling to the text area:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Number of rows in height: 12&lt;/li&gt;
&lt;li&gt;Number of Columns in width: 38&lt;/li&gt;
&lt;li&gt;Wrap attribute: virtual
&lt;em&gt;(The wrap attribute specifies how the text in a text area is to be wrapped when submitted in a form. &lt;code&gt;Wrap&lt;/code&gt; when set to &lt;code&gt;virtual&lt;/code&gt; means long lines are wrapped in the &lt;code&gt;textarea&lt;/code&gt;, but are not wrapped in the data sent to the processing script.)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Text color is white and font size of text is set as 20px.&lt;/li&gt;
&lt;li&gt;Background color is set as black for the text area.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A button is also placed with value &lt;code&gt;Calculate Words&lt;/code&gt;, which on pressing will show the results of the number of words i.e. invoke the &lt;code&gt;Countit()&lt;/code&gt; function. And a text area is specified which will display the output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--Code Segment4--&amp;gt;
&amp;lt;script type="text/javascript"&amp;gt;
    function Countit()
    {
      var formcontent = document.wordcount.wordcount2.value
      formcontent = formcontent.split(" ")
      document.wordcount.wordcount3.value = formcontent.length
    }
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have created a function named &lt;code&gt;Countit()&lt;/code&gt; inside the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag. Inside this function, we have initiated a String object &lt;code&gt;formcontent&lt;/code&gt; which will hold the text being entered by the user, referenced by the document element names. Then, we call the &lt;code&gt;split()&lt;/code&gt; function on the String object and store the result in the same object.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Use of split() function:&lt;/strong&gt;&lt;br&gt;
Split a string into an array of substrings&lt;br&gt;
Eg:&lt;br&gt;
&lt;em&gt;var str = "How are you doing today?";&lt;/em&gt;&lt;br&gt;
&lt;em&gt;var res = str.split(" ");&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Output:&lt;/em&gt;&lt;br&gt;
&lt;em&gt;["How", "are", "you", "doing", "today?"]&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then we count the length of the array String object &lt;code&gt;formcontent&lt;/code&gt; using the length attribute of the array and output the result in the value attribute of the text element &lt;code&gt;wordcount3&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--Code Segment5--&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the ending of the code segment.&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H-zPV5aA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ty1vublfxqzyofg9agg3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H-zPV5aA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ty1vublfxqzyofg9agg3.png" alt="img"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Thanks for Reading,
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Keep an eye on the next few articles on the same series.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Follow: &lt;a href="https://dev.to/subhajit_saha"&gt;@subhajit_saha&lt;/a&gt;
&lt;/h4&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>introduction</category>
    </item>
  </channel>
</rss>
