Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Firefox: window.getSelection does not work for text boxes.

Reply
Thread Tools

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

 
 
riog
Guest
Posts: n/a
 
      10-11-2007
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

 
Reply With Quote
 
 
 
 
riog
Guest
Posts: n/a
 
      10-11-2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview Sorting does not work after dynamically changing the Header text pargat.singh@gmail.com ASP .Net 0 04-24-2007 07:07 PM
why does Response.ContentType = "text/plain"; not work correctly? =?Utf-8?B?bGV0dWNlIGRhbmNl?= ASP .Net 3 10-26-2006 06:39 PM
MS work around on text wrapping in a datagrid does not work TB ASP .Net 2 02-22-2006 10:34 PM
Webservice works once and then DOES NOT seem to work even though program does not crash Phi! ASP .Net Web Services 1 04-23-2004 08:42 AM
asp:label in asp:datalist - Setting Text Value Does not work! Harry ASP .Net 3 04-16-2004 01:47 AM



Advertisments