Inserting UBB-Style Tags with IE and Mozilla

J

Jörg Dembski

Betreff: UBB-Style tags with IE and Mozilla
Von: Jörg Dembski <[email protected]>
Gruppen: comp.lang.javascript
Datum: Thu, 08 Jul 2004 17:49:29 +0200

Hey,

i got a code-snippet to insert around a selected text
in a textarea html-form inputfield.
This code works fine with IE, but with Opera / Mozilla / Konqueror
just nothing happens.

Here is the code snippet:

var seltext = null;
var repltext = null;
function InsertTag(strOpen,strClose)
{
seltext = (document.all)?
document.selection.createRange() : document.getSelection();
var selit = (document.all)?
document.selection.createRange().text : document.getSelection();
if (selit.length>=1)
{
if (seltext)
{
repltext= strOpen + selit + strClose;
if ((repltext=='')||(repltext==null)) repltext=seltext.text;
seltext.text = repltext;
window.focus()
}
}
else
{
alert(document.frmTest.strHTML.caretPos)
}
}


And then in the html-form:
<input type="button" value="B" onclick="javascript:InsertTag('', '');">


As i said, IE works fine. Mozilla won't :(


Thx for any help in advance
 
M

Michael Schmitt

Hi Jörg,

after a short look everything looks all right to me, except...

Jörg Dembski said:
Betreff: UBB-Style tags with IE and Mozilla
Von: Jörg Dembski <[email protected]>
Gruppen: comp.lang.javascript
Datum: Thu, 08 Jul 2004 17:49:29 +0200

Hey,

i got a code-snippet to insert around a selected text
in a textarea html-form inputfield.
This code works fine with IE, but with Opera / Mozilla / Konqueror
just nothing happens.

Here is the code snippet:

var seltext = null;
var repltext = null;
function InsertTag(strOpen,strClose)
{
seltext = (document.all)?
document.selection.createRange() : document.getSelection();
var selit = (document.all)?
document.selection.createRange().text : document.getSelection();
if (selit.length>=1)
{
if (seltext)
{
repltext= strOpen + selit + strClose;
if ((repltext=='')||(repltext==null)) repltext=seltext.text;
seltext.text = repltext;
window.focus()
}
}
else
{
alert(document.frmTest.strHTML.caretPos)
}
}


And then in the html-form:
<input type="button" value="B" onclick="javascript:InsertTag('', '');">

the onclick event handler expects valid javascript code, so there is no reason
(and it's probably wrong), to write "javascript:...".
Try it this way and it should work:

<input type="button" value="B" onclick="InsertTag('', '');">
or maybe said:
As i said, IE works fine. Mozilla won't :(


Thx for any help in advance

regards, Michael
 
M

Michael Schmitt

Michael said:
or maybe <input type="button" value="B"
onclick="javascript:InsertTag('<b>', '</b>');"> ?

a copy and paste error, it should read
<input type="button" value="B" onclick="InsertTag('<b>', '</b>');">

cu, Michael
 

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

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,087
Members
48,773
Latest member
Kaybee

Latest Threads

Top