Firefox: window.getSelection does not work for text boxes.

Discussion in 'Javascript' started by riog, Oct 11, 2007.

  1. riog

    riog Guest

    Hi,

    Im trying to get the selected text from a textbox. window.getSelection
    does not work in Firefox. Can you provide a solution or work-around
    for this?

    Here's my code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <META http-equiv="Content-Type" content="text/html;
    charset=ISO-8859-1">
    <TITLE>test.html</TITLE>
    <style type="text/css">
    #result { font-style:italic;border:1px solid; height:100px;
    overflow:auto;}
    </style>
    <SCRIPT type="text/javascript">
    function okButtonClickListener() {
    document.getElementById("result").innerHTML =
    window.getSelection();
    }
    function inputTextKeypressListener() {
    document.getElementById("result").innerHTML = window.getSelection();
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <input type="text" onkeypress="inputTextKeypressListener();"/>
    <p>
    Select a text and mouse over here to view selection text (or click the
    Ok button).
    </p>
    <b>Input Text Selection:</b><div id="result"
    onmouseover="inputTextKeypressListener()"></div>
    <input type="button" value="Ok" onclick='okButtonClickListener();'/>
    </BODY>
    </HTML>

    Thanks,
    riog
     
    riog, Oct 11, 2007
    #1
    1. Advertising

  2. riog

    riog Guest

    Here's the revised code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <META http-equiv="Content-Type" content="text/html;
    charset=ISO-8859-1">
    <TITLE>test.html</TITLE>
    <style type="text/css">
    #result { font-style:italic;border:1px solid; height:100px;
    overflow:auto;}
    </style>
    <SCRIPT type="text/javascript">
    function okButtonClickListener() {
    document.getElementById("result").innerHTML =
    window.getSelection();
    }
    function inputTextKeypressListener() {
    document.getElementById("result").innerHTML = window.getSelection();
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <input type="text" onkeypress="inputTextKeypressListener();"/>
    <p>
    Select a text and mouse over the DIV below to view selected text (or
    click the Ok button).
    </p>
    <b>Input Text Selection:</b><div id="result"
    onmouseover="inputTextKeypressListener()"></div>
    <input type="button" value="Ok" onclick='okButtonClickListener();'/>
    </BODY>
    </HTML>

    Thanks,
    riog
     
    riog, Oct 11, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Crowe
    Replies:
    1
    Views:
    4,550
    Andrew Crowe
    Sep 13, 2004
  2. John Allsopp

    Safari window.getSelection()

    John Allsopp, May 13, 2004, in forum: Javascript
    Replies:
    0
    Views:
    170
    John Allsopp
    May 13, 2004
  3. Jason Quinn

    possible to getSelection from AJAX sites?

    Jason Quinn, Apr 18, 2007, in forum: Javascript
    Replies:
    1
    Views:
    99
    Peter Michaux
    Apr 21, 2007
  4. riog

    window.getSelection on a textbox

    riog, Oct 17, 2007, in forum: Javascript
    Replies:
    1
    Views:
    130
    Thomas 'PointedEars' Lahn
    Oct 17, 2007
  5. RobG
    Replies:
    2
    Views:
    414
    Dr J R Stockton
    Jul 16, 2011
Loading...

Share This Page