Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have written following code to get the data from textarea those input by user and show that data on the div(odiv3) after clicking on "ok" button;

How i can show this data on div ?


HTML


XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Three Div Tags</title>
<script  type ="text/javascript" language ="javascript"  >
<script  type ="text/javascript" language ="javascript"  >
function showDiv1()
{
 
document.getElementById('Div1').innerHTML=document.getElementById('TextArea1').value;
return false;
}
    </script>


<input type="submit" id="btn" value="ok" onclick="return showDiv1();" />



<style type="text/css">
#odiv1{
    margin:3px;

    background-color:#333333;
    height:400px;
    width:460px;
}
#odiv2{
background-color:#0066FF;
margin-left:8px;
    margin-top:15px;

    height:200px;
    width:200px;
    float:left;

}
#odiv3{ overflow:Auto;
margin-top:12px;

   float:right;
    background-color: #00FF66;
    height:340px;
    width:200px;

}
</style>

</head>

<body>
<form name="form">
<div id="odiv1"><p align="left">odiv1</p>
<div id="odiv2">div2<br>
  <textarea  id="text" name="text" cols="20"  rows="5"></textarea>
</br></div>
<div id="odiv3">odiv3<br>
  </br></div>
</div>

   </form>
</body>
</html>




I want to do this using html and javascript not in jquery...


Thanks in advance,
Sandra
Posted

Try this:
XML
<!DOCTYPE html>
<head>
<title>Three Div Tags</title>
<script>
function showDiv1()
{
   odiv2Value = document.getElementById('text').value;
   // replace JavaScript line break with HTML <br>
   odiv2Value = odiv2Value.replace(/(?:\r\n|\r|\n)/g, '<br>');
   document.getElementById('odiv3').innerHTML=odiv2Value ;
   return false;
}
</script>
</head>
<body>
<form name="form">
<div id="odiv1"><p align="left">odiv1</p>
<div id="odiv2">div2<br>
  <textarea  id="text" name="text" cols="20"  rows="5"></textarea>
</br></div>
<div id="odiv3">odiv3<br>
  </br></div>
</div>
 <input type="submit" id="btn" value="ok" onclick="return showDiv1();">
</form>
</body>
</html>
 
Share this answer
 
v4
Comments
Sanjita Priya 5-Jan-15 2:22am    
it's not working...
Peter Leow 5-Jan-15 2:29am    
There was a little typo, corrected.
Sanjita Priya 5-Jan-15 2:33am    
Thank you... If I'll do the same concept for copy text from text area in one page to the div section in another page is that any problem in that???
How about using such a convenient and robust library as jQuery:
http://en.wikipedia.org/wiki/JQuery[^],
http://jquery.com/[^]?

This is what you would need:
http://api.jquery.com/category/selectors/[^],
http://api.jquery.com/html[^],
http://api.jquery.com/category/manipulation/dom-insertion-inside/[^].

If you need to learn jQuery (highly recommended), please see:
http://learn.jquery.com[^],
http://learn.jquery.com/using-jquery-core[^],
http://learn.jquery.com/about-jquery/how-jquery-works[^] (start from here).

—SA
 
Share this answer
 
v3
Comments
Sanjita Priya 5-Jan-15 2:13am    
I don't know jquery programming and I need to do in javascript for my project...
Sergey Alexandrovich Kryukov 5-Jan-15 2:41am    
Okay, do you want to reinvent the wheel? Yes, you can, but it would be just the boring waste of time.
What do you mean, "need to do in javascript"? What do you think I've suggested, not Javascript? What you wrote is nonsense, sorry.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900