473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Textbox + Javascript

Hi,
Please can you help me,
I have seen some free JavaScript that has a text box, with buttons under it
Bold, Italic, Underline, so when the text in the box is highlighted, it puts
the HTML code around the selected text.

But I can not now find it .... do you know where an example is?

Many thanks
Mike.
Jul 20 '05 #1
2 5178
In article <6m*****************@newsfep4-winn.server.ntli.net>, mike42
@ntlworld.com enlightened us with...
Hi,
Please can you help me,
I have seen some free JavaScript that has a text box, with buttons under it
Bold, Italic, Underline, so when the text in the box is highlighted, it puts
the HTML code around the selected text.

But I can not now find it .... do you know where an example is?

Many thanks
Mike.


Note: IE only
Netscape/Mozilla have a way to get selected text, but it doesn't play
nice with input elements like textareas. Opera has no way to write to
the selection. No way found for other browsers.

<html>
<head>
<title> Adding HTML tags to selected text - IE only</title>
<script type="text/javascript" language="javascript">
function doTag(which)
{
// IE only - netscape's range object doesn't work well with textareas
if (document.selection)
{
switch (which)
{
case "bold":
s = document.selection.createRange().text;
document.selection.createRange().text = "<b>"+s+"</b>";
break;
case "italic":
s = document.selection.createRange().text;
document.selection.createRange().text = "<i>"+s+"</i>";
break;
}
}
}
</script>

</head>

<body>
<form name="f1" action="" method="get" onSubmit="return false">
<p>Work area: <textarea cols="50" rows="10" name="workarea"
id="workarea"></textarea></p>
<p>
<input type="button" name="b_bold" id="b_bold" onClick="doTag('bold')"
value="BOLD"> &nbsp;
<input type="button" name="b_italic" id="b_italic" onClick="doTag
('italic')" value="ITALIC"> &nbsp;
</p>
</form>
</body>
</html>
--
--
~kaeli~
Why did kamikaze pilots wear helmets?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
Thats great - and works well - many thanks

also
thanks to Simon Wigzell who sent me some advice.

Regards
Mike.
"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <6m*****************@newsfep4-winn.server.ntli.net>, mike42
@ntlworld.com enlightened us with...
Hi,
Please can you help me,
I have seen some free JavaScript that has a text box, with buttons under it Bold, Italic, Underline, so when the text in the box is highlighted, it puts the HTML code around the selected text.

But I can not now find it .... do you know where an example is?

Many thanks
Mike.


Note: IE only
Netscape/Mozilla have a way to get selected text, but it doesn't play
nice with input elements like textareas. Opera has no way to write to
the selection. No way found for other browsers.

<html>
<head>
<title> Adding HTML tags to selected text - IE only</title>
<script type="text/javascript" language="javascript">
function doTag(which)
{
// IE only - netscape's range object doesn't work well with textareas
if (document.selection)
{
switch (which)
{
case "bold":
s = document.selection.createRange().text;
document.selection.createRange().text = "<b>"+s+"</b>";
break;
case "italic":
s = document.selection.createRange().text;
document.selection.createRange().text = "<i>"+s+"</i>";
break;
}
}
}
</script>

</head>

<body>
<form name="f1" action="" method="get" onSubmit="return false">
<p>Work area: <textarea cols="50" rows="10" name="workarea"
id="workarea"></textarea></p>
<p>
<input type="button" name="b_bold" id="b_bold" onClick="doTag('bold')"
value="BOLD"> &nbsp;
<input type="button" name="b_italic" id="b_italic" onClick="doTag
('italic')" value="ITALIC"> &nbsp;
</p>
</form>
</body>
</html>
--
--
~kaeli~
Why did kamikaze pilots wear helmets?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
9
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
4
by: Dabbler | last post by:
Is there a way to mark the text in a TextBox control as selected so when the user types a new value the existing text is replaced? Thanks
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
6
by: HockeyFan | last post by:
I'd like to have an AJAX textbox that after the user fills in, will auto-fill another textbox on the page without having a postback occur. It doesn't have to do any filtering or any other thing...
2
by: mc | last post by:
Can someone suggest how I would add a new trigger such that when the JS event onkeyup in a textbox the updatePanel refreshes? If not could someone sugest how I could onkepup in a Textbox, refresh...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
2
by: =?Utf-8?B?SmVycnkgSg==?= | last post by:
Hello, I am using asp.net 2003 using C#. I am creating textboxes dynamically and want to validate to make sure the user can only input an integer. I don't think I can use the validators...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.