to select a string from textarea

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jan 2008
Posts: 71
Reputation: ajithraj is an unknown quantity at this point 
Solved Threads: 1
ajithraj ajithraj is offline Offline
Junior Poster in Training

to select a string from textarea

 
0
  #1
Jan 23rd, 2008
haii friends....
i want to select a particular string from textarea...i need it in javascript....
am using the tag <layout:textarea>
i did not need the whole ,but only a part...plzz help me...
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,087
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: to select a string from textarea

 
0
  #2
Jan 23rd, 2008
Originally Posted by ajithraj View Post
haii friends....
i want to select a particular string from textarea...i need it in javascript....
am using the tag <layout:textarea>
i did not need the whole ,but only a part...plzz help me...
What markup language are you using?

In HTML a text area is just <textarea>.

You'll need a reference to the DOM node representing the text area, example:

textarea HTML
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <textarea id="mytext">
  2. </textarea>

select whats inside the textarea with JS
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. // get the textarea by its id
  2. var txt = document.getElementById('mytext');
  3. // theres the contents inside the textarea
  4. var value = txt.value;
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,087
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: to select a string from textarea

 
0
  #3
Jan 23rd, 2008
btw: once you have the value of the string, you need to do some matching with regex or similar to get what you want out of the string.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: ajithraj is an unknown quantity at this point 
Solved Threads: 1
ajithraj ajithraj is offline Offline
Junior Poster in Training

Re: to select a string from textarea

 
0
  #4
Jan 24th, 2008
Originally Posted by ajithraj View Post
haii friends....
i want to select a particular string from textarea...i need it in javascript....
am using the tag <layout:textarea>
i did not need the whole ,but only a part...plzz help me...
thankzzz....
am using struts framework and <layout:textarea> is provided in it..
it has no property like "id" (ie..<textarea id="">)....
its syntax is like this..
<layout:textarea property="' key=""></layout:textarea>

"property" is used to represent the textarea ....

and wht is ment by "getElementById"..plzzz help
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,087
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: to select a string from textarea

 
0
  #5
Jan 24th, 2008
Originally Posted by ajithraj View Post
thankzzz....
am using struts framework and <layout:textarea> is provided in it..
it has no property like "id" (ie..<textarea id="">)....
its syntax is like this..
<layout:textarea property="' key=""></layout:textarea>

"property" is used to represent the textarea ....

and wht is ment by "getElementById"..plzzz help
You'll need to find out how to render HTML attributes using struts.

-----

Re: getElementById

Once the HTML is rendered on the page, the browser will create a DOM (Document Object Model) representation of the HTML for programmatic access from JavaScript.

The DOM is a W3C specification that models XML data as Objects. It is quite simple. Take for example some XML:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <root>
  2. <child1 id="child1_id">Im a child of root</child1>
  3. <child2 id="child2_id">
  4. <subchild1 id="subchild1_id">Im a child of child2</subchild1>
  5. </child2>
  6. </root>

There are many ways to model this XML document. The model used in browsers is the DOM. So in JavaScript, if you have a reference to the XML Document you could traverse it and select elements (DOM nodes) as well as manipulate it.

If the XML document reference is: XMLDoc, then the root would be:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. XMLDoc.documentElement;

<child1> would be:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. XMLDoc.documentElement.firstChild

or

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. XMLDoc.documentElement.childNodes.item(0);

or

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. XMLDoc.documentElement.getElementsByTagName('child1').item(0);

or

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. XMLDoc.documentElement.getElementsById('child1_id');

(These are all example of DOM methods for selecting Nodes/Elements).

getElementsById('child1_id') selects the child Node/Element with the id attribute 'child1_id'.

In HTML, the DOM is already created by the browser and available through document object. So you can use document to select any HTML element using DOM methods.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById('any_id_in_the_html_document');
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: ajithraj is an unknown quantity at this point 
Solved Threads: 1
ajithraj ajithraj is offline Offline
Junior Poster in Training

Re: to select a string from textarea

 
0
  #6
Jan 24th, 2008
kk thankzzz.....
is there any method in java like "selectionStart"
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,087
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: to select a string from textarea

 
0
  #7
Jan 24th, 2008
Originally Posted by ajithraj View Post
kk thankzzz.....
is there any method in java like "selectionStart"
Do you want to get the Text that the user has currently selected?
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: ajithraj is an unknown quantity at this point 
Solved Threads: 1
ajithraj ajithraj is offline Offline
Junior Poster in Training

Re: to select a string from textarea

 
0
  #8
Jan 25th, 2008
Originally Posted by digital-ether View Post
Do you want to get the Text that the user has currently selected?
yes......i need that....
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,087
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: to select a string from textarea

 
0
  #9
Jan 25th, 2008
Originally Posted by ajithraj View Post
yes......i need that....
See: http://www.quirksmode.org/dom/range_intro.html
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: ajithraj is an unknown quantity at this point 
Solved Threads: 1
ajithraj ajithraj is offline Offline
Junior Poster in Training

Re: to select a string from textarea

 
0
  #10
Jan 28th, 2008
Originally Posted by digital-ether View Post
See: http://www.quirksmode.org/dom/range_intro.html
thankzzzzzzz a lottt
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 4468 | Replies: 9
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC