[WSG] FireFox DOM issue.

2005-08-09 Thread Buddy Quaid
Hi everyone,

I'm new to this group and this is my first message.

I am porting over a rich text editor that currently only works in IE.

I have done tons of search about getting the selected text in a page.
I'm very close...for instance...you can now see the formatting buttons
and also I have the correct code to get it to know what is selected and
if you click 'bold' it will put the bold tags around it in a text box.

I want it so that if NOTHING is selected and you hit bold it will give
you an alert box for the text that you would like bolded. Then plance
that text with the bold tags around it. My problem is I can't get the
right code of the DOM to test correctly for a selection being made in
the text box.

I am currently trying

Str = window.getSelection;
If (str.isCollapsed) {
   if true do this;
}else{
do this;
}

I put alert(str.isCollapsed) in there to trace what is going on but it's
ALWAYS true.

I'm wondering if it's because the text is in a textarea and not just on
the page?

Like I said, I have been getting it to work without sniffing to see if a
selection has actually been made to put the tags around the text but I
can't for the life of me sniff it out through code.

I've also tried 

Str = window.getSelection;
If(str.toString().length  0) to no avail.

Thanks in advance!

Buddy

**
The discussion list for  http://webstandardsgroup.org/

 See http://webstandardsgroup.org/mail/guidelines.cfm
 for some hints on posting to the list  getting help
**



Re: [WSG] FireFox DOM issue.

2005-08-09 Thread Patrick Ryan
In firefox, I have had success with selectionStart and selectionEnd

if you have a form:
form name=a
   textarea name=b/textarea

you can access the start and end points of the highlighted text (or
get the position of the cursor in the text) with:

startPoint = document.a.b.selectionStart;
endPoint = document.a.b.selectionEnd;

This won't work in IE (where I tend to use document.selection) so you
have to do some kind of functionality test like:

if(document.selection){ 
//do IE stuff
}else if(myField.selectionStart)
//do mozilla stuff



Hope this helps

-- 
Patrick
www.agavegroup.com



On 8/9/05, Buddy Quaid [EMAIL PROTECTED] wrote:
 Hi everyone,
 
 I'm new to this group and this is my first message.
 
 I am porting over a rich text editor that currently only works in IE.
 
 I have done tons of search about getting the selected text in a page.
 I'm very close...for instance...you can now see the formatting buttons
 and also I have the correct code to get it to know what is selected and
 if you click 'bold' it will put the bold tags around it in a text box.
 
 I want it so that if NOTHING is selected and you hit bold it will give
 you an alert box for the text that you would like bolded. Then plance
 that text with the bold tags around it. My problem is I can't get the
 right code of the DOM to test correctly for a selection being made in
 the text box.
 
 I am currently trying
 
 Str = window.getSelection;
 If (str.isCollapsed) {
if true do this;
 }else{
 do this;
 }
 
 I put alert(str.isCollapsed) in there to trace what is going on but it's
 ALWAYS true.
 
 I'm wondering if it's because the text is in a textarea and not just on
 the page?
 
 Like I said, I have been getting it to work without sniffing to see if a
 selection has actually been made to put the tags around the text but I
 can't for the life of me sniff it out through code.
 
 I've also tried
 
 Str = window.getSelection;
 If(str.toString().length  0) to no avail.
 
 Thanks in advance!
 
 Buddy
 
 **
 The discussion list for  http://webstandardsgroup.org/
 
  See http://webstandardsgroup.org/mail/guidelines.cfm
  for some hints on posting to the list  getting help
 **
 

**
The discussion list for  http://webstandardsgroup.org/

 See http://webstandardsgroup.org/mail/guidelines.cfm
 for some hints on posting to the list  getting help
**