Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

document.getSelection in Frames

Posted on 1998-09-24
3
Medium Priority
?
635 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 800 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

618 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