Solved

document.getSelection in Frames

Posted on 1998-09-24
3
611 Views
Last Modified: 2012-08-14
Can someone make the following script work in frames?  I need the selection from one frame to appear in the text area  in another frame.  In other words, when I select the text in frame 1, the selection will automatically appear in the text box in frame 2.
<HTML>
<BODY>
<P>text text</P>
<P>something else</P>
<P>More text</P>
<FORM NAME="aForm">
<A NAME="A"></A><FONT FACE="Arial,Helvetica" SIZE=-1>Part Name:&nbsp;</FONT>&nbsp;<INPUT TYPE=TEXT NAME="aName" SIZE=50>&nbsp;

</FORM>
</BODY>
</HTML>

<SCRIPT LANGUAGE="JavaScript">
        <!--

        function display() {
          if (document.getSelection) {
            var str = document.getSelection();
            if (window.RegExp) {
              var regstr = unescape("%20%20%20%20%20");
              var regexp = new RegExp(regstr, "g");
              str = str.replace(regexp, "");
            }
          } else if (document.selection && document.selection.createRange) {
            var range = document.selection.createRange();
            var str = range.text;
          } else {
            var str = "Sorry, this is not possible with your browser.";
          }
          document.aForm.aName.value = str;
        }

        if (window.Event)
          document.captureEvents(Event.MOUSEUP);
        document.onmouseup = display;

        // -->
        </SCRIPT>

I got it from webreference.com.

Kurt
0
Comment
Question by:kmartin7
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
martinag earned 200 total points
ID: 1271334
Index.htm
------
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<FRAMESET COLS="50%,*">
<FRAME SRC="left.htm">
<FRAME SRC="right.htm" NAME="formFrame">
</FRAMESET>
</HEAD>
<NOFRAMES>
<BODY>
Sorry, your browser does not support frames.
</BODY>
</NOFRAMES>
</HTML>

left.htm
------

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function display() {
  if (document.getSelection) {
    var str = document.getSelection();
    if (window.RegExp) {
      var regstr = unescape("%20%20%20%20%20");
      var regexp = new RegExp(regstr, "g");
      str = str.replace(regexp, "");
    }
  }
  else if (document.selection && document.selection.createRange) {
    var range = document.selection.createRange();
    var str = range.text;
  }
  else {
    var str = "Sorry, this is not possible with your browser.";
  }
  parent.formFrame.document.aForm.aName.value = str;
}

if (window.Event)
document.captureEvents(Event.MOUSEUP);
document.onmouseup = display;

// -->
</SCRIPT>
</HEAD>
<BODY>
<P>text text</P>
<P>something else</P>
<P>More text</P>
</BODY>
</HTML>

right.htm
------
<HTML>
<BODY>
<FORM NAME="aForm">
<A NAME="A"></A><FONT FACE="Arial,Helvetica" SIZE=-1>Part   Name:&nbsp;</FONT>&nbsp;<INPUT TYPE=TEXT NAME="aName" SIZE=50>&nbsp;
</FORM>
</BODY>

Martin
0
 
LVL 11

Author Comment

by:kmartin7
ID: 1271335
parent.formFrame

Boy, do I feel stupid.  Here's the 200 points, Martin.


Kurt
0
 
LVL 4

Expert Comment

by:martinag
ID: 1271336
Thank you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
document.write() deleting all existing HTML 5 51
jQuery Dialog Autoresize Bug 2 25
How to make a good PHP + MySQL + JS pagination system? 3 33
Search Item in Table 2 22
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question