Jump to content

getting selected text from text area


ps_sach

Recommended Posts

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'

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...

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.