How to get text area output in JavaScript

Hey Folks,
I am here with another tutorial of JavaScript. In this tutorial, we will learn how to get text area output in JavaScript. This feature of JavaScript we mostly use in billing websites. Because the information we enter is displayed at checkout.

We use onClick() function to give output at click of a button. So let’s start our tutorial on how to get text area output. Let’s divide our code into two parts.

Code to get output in Text Area

We set our form name as frm so it would be easier for us. We create a function named find(). And also we make if and else condition for the to radio buttons. As we have to keep a track which radio button is clicked. But we don’t do the same with check boxes. As one or more check boxes can be selected.



And also all check boxes have a different name. We store value of all text in different variables. And at last we sum up all the variables and assign it to text box named t3.

<!DOCTYPE html>
<script>
function find()
{
var a,b,c,d
c=" "
d=" "
a=document.frm.t1.value
b=document.frm.t2.value
if(document.frm.r[0].checked)
c="male"
else if(document.frm.r[1].checked)
c="female"
if(document.frm.c1.checked)
d="cricket" +d
if(document.frm.c2.checked)
d="football" +d
document.frm.t3.value=a + " " + b + " " + c + " " + d
}
</script>
<form name="frm">
Name
<input type="text" name="t1">
<br>Password
<input type="password" name="t2">
<br>Male
<input type="radio" name="r">
Female
<input type="radio" name="r">
<br>Cricket
<input type="checkbox" name="c1">
Football
<input type="checkbox" name="c2">
<br>
<textarea rows="6" cols="14" name="t3">
</textarea>
<br><input type="button" value="click" onClick="find()">
</form>



 

In form tag we create name of type text and password of type password. But we keep names of all these text boxes different in order to use them in script tag.

I hope you understood the code. Feel free to ask your doubts in comment below.

You must also read,

Leave a Reply

Your email address will not be published. Required fields are marked *