Solved

document.getSelection in Frames

Posted on 1998-09-24
3
624 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

726 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