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

R

riog

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
 
R

riog

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top