Solved

document.getSelection in Frames

Posted on 1998-09-24
3
610 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

770 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