C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







How to retrieve selected text from a textbox or textarea


Posted Date: 01 May 2008    Resource Type: Code Snippets    Category: Javascript

Posted By: Asha Mathews       Member Level: Gold
Rating:     Points: 20



the text highlighted is saved and shown in a popup in this example, but we can use it in any applications. (this is similar to T-SQL query execution process, in which we can execute only the highlighted portion).


<script language=javascript>
function getSelText()
{

var txt = '';
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
else return;

//var mytxt = txt;
//document.getElementById("selectedtext").value = txt;

alert(txt);
alert(document.getElementById("selectedtext").value);

}
</script>



<html>
<form name=aform action="" >
<textarea name="selectedtext" rows="5" cols="20" ></textarea><br />
<input type="button" value="Get selection" onClick="getSelText()">
</form>
</html>




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to create Namespace in Javascript
Previous Resource: Generate Dynamic textbox in client using JAVASCRIPT
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use