Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-01-2006, 11:19 PM   PM User | #1
khorask
New to the CF scene

 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
khorask is an unknown quantity at this point
Selected Text

Im trying to make a simple txt/html editor...

I need to apply specific formatting to selected text via a button.
for example, I select some text, click the 'bold' button which then replace the selected text with <b>selected text</b>

Is there a way to do this ?
thanks
khorask is offline   Reply With Quote
Old 05-02-2006, 01:22 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
For IE is rather simple:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<
html>
<
head>
<
title>Untitled Document</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<
meta http-equiv="Content-Style-Type" content="text/css">
<
meta http-equiv="Content-Script-Type" content="text/javascript">
<
script type="text/javascript">
function 
getSel(tag,endtag){
var 
txt='';
if(
document.selection){
txt document.selection.createRange().text
document
.selection.createRange().text=txt.replace(new RegExp(txt),tag+txt+endtag)
}
else{return}
}
</script>
</head>
<body>
<input name="bold" type="button" value=" B " style="font-weight:bold"onclick="getSel('<strong>','</strong>')"> Bold <input name="italic" type="button" value=" I " style="font-weight:bold;font-style:italic"onclick="getSel('<em>','</em>')"> Italic<br><br>
<textarea cols="50" rows="10">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</textarea>
</body>
</html> 
For Moz is quite intricate. I'll have to test later some DOM methods to try to find an equivalent (does anyone has something like that?)
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 12:30 PM.


Advertisement
Log in to turn off these ads.