473,379 Members | 1,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

capture selected text from a page

can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse out.

here is the code

[HTML]<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var captured = "";
function captext()
{
alert('You have selected'+ captured);
}
var text = "";
function getActiveText(e) {

// Sets text MSIE or Netscape active
// text based on browser, puts text in form
text = (document.all) ? document.selection.createRange().text : document.getSelection();
captured = text;
captext();
document.theform.text.value = text;
return true;
}
document.onmouseup = getActiveText;
if (!document.all) document.captureEvents(Event.MOUSEUP);
// End -->
</script>
<script type="text/javascript">
function popup()
{
var wind1=null;
var tmp=null;
wind1 = window.open('', 'displayWindow', 'width=400,height=300,status=no,toolbar=no,menubar =no,scrollbars=1');
wind1.document.write("<script> function alert1(f){");
wind1.document.write("var frmdst=f.ta.value;");
wind1.document.write("window.opener.tmp=frmdst;");
wind1.document.write("window.opener.getValues();") ;
wind1.document.write("window.close();");
wind1.document.write("}<\/script>");
wind1.document.write("<html><body><form action='#' name='myform' method='post'><TEXTAREA rows='2' cols='20' name='ta'></TEXTAREA><br><INPUT type='button' value='save' onclick='javascript:alert1(this.form);'><INPUT type='button' value='cancel' onclick='javascript:window.close();'></form></body></html>");
}
function getValues()
{
document.forms["source"].elements["srctext"].value = tmp;
}
</script>
</HEAD>
<BODY>

<center>
<form name=theform>
Selected text: <input type=text name=text value="" size="20">
<br><br>
Entered text: <input type=text name=text1 value="" size="20">
</form>
</center>

<p>
<p>Hi All,</p>
<p>&nbsp;</p>
<p>this is the javascript that will capture the value highlighted and store in a
variable.</p>

</body>
</html>[/HTML]
Mar 19 '08 #1
1 2738
acoder
16,027 Expert Mod 8TB
can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse out.
You mean mouseup? It depends on your requirements. Maybe you want to call it when a button is clicked?
Mar 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: George Hester | last post by:
When the address bar is highligted? That is nothing on the page is selected. The address bar is selected. Capture keydown or keypress? Any ideas using javascript? Thanks. -- George Hester...
9
by: lkrubner | last post by:
I've got a function, you can see it below, that is being called onmouseup in the textarea on my main form. The idea is to find a selection if possible and store that text in a global variable. I...
1
by: Hose B | last post by:
HI all, I have a legacy app in which users can pick various page templates. There is a template preview dialog. It works such that they view a list of icons in an asp page that represent each...
3
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
3
by: Figmo | last post by:
I am writing a language translation app. It will run minimized to the tray. I want to setup a global hotkey that a user can hit that will capture whatever text is highlighted in the current...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
13
by: =?Utf-8?B?RG9uYWxkIEZpc2hlcg==?= | last post by:
Hello. I'm trying to capture a controls value: a dropdown box with two selections (either "Red" or "Blue") keeps returning the value "Red" even if "Blue" is selected?
5
by: vasilis | last post by:
I have a list box in a site with which I capture a selected value with the onChange event using the capture_value() function (code listed below). This function passes 2 arguments, i.e., 'str' which...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.