Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2012, 08:37 AM   PM User | #1
learner guy
New Coder

 
Join Date: Jul 2011
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
learner guy is an unknown quantity at this point
assign content of textarea to a div as in twitter

i want to assign content of textarea to a div .. like in twitter when you type something and press "Tweet" a div is created and has the content of textarea..
how can i implement it , i know something about getElementById() but not sure how it can help me here
learner guy is offline   Reply With Quote
Old 01-23-2012, 09:43 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Example

HTML
Code:
<textarea id="mytext"></textarea>
<div id="container">
</div>
<button id="tweetit" onclick="tweetit();">Tweet</button>
Javascript
Code:
function tweetit() {
   var newDIV = document.createElement('div');
   newDIV.className = "whatEverYouNeedForStyling";
   newDIV.innerHTML = document.getElementById('mytext').value; // put textarea value into new DIV
   document.getElementById('container').appendChild(newDIV); // append new DIV to container
}
devnull69 is offline   Reply With Quote
Old 01-23-2012, 12:55 PM   PM User | #3
learner guy
New Coder

 
Join Date: Jul 2011
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
learner guy is an unknown quantity at this point
Quote:
Originally Posted by devnull69 View Post
Example

HTML
Code:
<textarea id="mytext"></textarea>
<div id="container">
</div>
<button id="tweetit" onclick="tweetit();">Tweet</button>
Javascript
Code:
function tweetit() {
   var newDIV = document.createElement('div');
   newDIV.className = "whatEverYouNeedForStyling";
   newDIV.innerHTML = document.getElementById('mytext').value; // put textarea value into new DIV
   document.getElementById('container').appendChild(newDIV); // append new DIV to container
}
can u explain the javascript part plz , what is 'div' , in
Code:
document.createElement('div');
is this fixed tagname of <div> or just a name

Last edited by learner guy; 01-23-2012 at 12:59 PM..
learner guy is offline   Reply With Quote
Old 01-23-2012, 12:59 PM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
I already explained the last two lines using comments in the code

The first two lines create a new DIV element "on the fly" and assign a class to it
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Tags
assign, content, div, htmldom, twitter

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:32 PM.


Advertisement
Log in to turn off these ads.