ps_sach Posted March 25, 2008 Share Posted March 25, 2008 <form name="form1" action=""> <input type="text area" name="area" width=20 height=10/> </form> i want to access the selected text from text area area in java script any one can give help..... Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/ Share on other sites More sharing options...
haku Posted March 25, 2008 Share Posted March 25, 2008 This is a javascript issue, not html, although there are errors in your html: <form action="path/to/file.php" method="post"> <textarea id="target" name="area" cols="20" rows="10"></textarea> </form> Here is the javascript you can use: <script type="text/javascript"> var targetText = document.getElementById("target").firstChild.data </script> The text in the textarea will then be contained in the javascript variable 'targetText' Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/#findComment-500132 Share on other sites More sharing options...
ps_sach Posted March 28, 2008 Author Share Posted March 28, 2008 This is a javascript issue, not html, although there are errors in your html: <form action="path/to/file.php" method="post"> <textarea id="target" name="area" cols="20" rows="10"></textarea> </form> Here is the javascript you can use: <script type="text/javascript"> var targetText = document.getElementById("target").firstChild.data </script> The text in the textarea will then be contained in the javascript variable 'targetText' thanks for the help...... you have given the code to get the whole text from the text area... But i want to access the selected text from the text area. for example... in java we can get the selected text form the text area as... suppose the textarea name is area then, string selectedText=area.getSelectedText(); i think this will be the function in java ,but i m not sure... Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/#findComment-502843 Share on other sites More sharing options...
haku Posted March 28, 2008 Share Posted March 28, 2008 java or javascript? Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/#findComment-502871 Share on other sites More sharing options...
ps_sach Posted March 29, 2008 Author Share Posted March 29, 2008 java or javascript? i have just given the example of the java ............. .......... but i want the javascript code ........ ....... Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/#findComment-503826 Share on other sites More sharing options...
nibbo Posted March 29, 2008 Share Posted March 29, 2008 You can use getSelected i.e for your text area use: document.getElementById('target').getSelected Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/#findComment-503958 Share on other sites More sharing options...
haku Posted March 31, 2008 Share Posted March 31, 2008 i have just given the example of the java I'm not a java programmer, so I don't know what it looks like. But the above sure looked like javascript to me. That's where my confusion arose - I don't know if you are talking about javascript or java. Which one are you talking about? Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/#findComment-505304 Share on other sites More sharing options...
nibbo Posted March 31, 2008 Share Posted March 31, 2008 My suggestion is JavaScript Quote Link to comment https://forums.phpfreaks.com/topic/97740-getting-selected-text-from-text-area/#findComment-505368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.