Selected text/function question

D

Dru

Hi,

I am making a textarea for people to add/modify their text for
descriptions products. I want to have buttons (or just text links)
with functions that will allow them to bold, italicize, sup, sub, etc
the text they have selected.

This is what I have come up with so far, it's not working though.

===========================================

<script language="JavaScript">
<!--
function createIt(Do1) {
myTextRange = document.News.NewsStory.createTextRange();
var newContent = "<" + Do1 + ">" + myTextRange + "</" + Do1 + ">";

document.News.NewsStory.value = newContent;
}
// -->
</script>

<body bgcolor="White" text="Black" id="myBody">

<form action="f_upload.htm" method="POST" name="News">

<textarea cols="46" rows="10" name="NewsStory"></textarea>

<img src="images/icons_fontB.gif"
onMouseOut="this.src='images/icons_fontB.gif'"
onMouseOver="this.src='images/icons_fontB2.gif'"
onClick="createIt('b');" alt="Bold">

<img src="images/icons_fontU.gif"
onMouseOut="this.src='images/icons_fontU.gif'"
onMouseOver="this.src='images/icons_fontU2.gif'"
onClick="createIt('u');" alt="Underline">

etc ...

</form>

===========================================

First off, is there code available out there that I can use? Otherwise
can someone let me know what I'm doing wrong here? The use of
createTextRange could be misused. Right now when I try this function I
get <b>[object]</b> if I click on and text and the bold link.

Any clues?

thnx
 
R

Reply Via Newsgroup

Dru said:
Hi,

I am making a textarea for people to add/modify their text for
descriptions products. I want to have buttons (or just text links)
with functions that will allow them to bold, italicize, sup, sub, etc
the text they have selected.

This is what I have come up with so far, it's not working though.

===========================================

<script language="JavaScript">
<!--
function createIt(Do1) {
myTextRange = document.News.NewsStory.createTextRange();
var newContent = "<" + Do1 + ">" + myTextRange + "</" + Do1 + ">";

document.News.NewsStory.value = newContent;
}
// -->
</script>

<body bgcolor="White" text="Black" id="myBody">

<form action="f_upload.htm" method="POST" name="News">

<textarea cols="46" rows="10" name="NewsStory"></textarea>

<img src="images/icons_fontB.gif"
onMouseOut="this.src='images/icons_fontB.gif'"
onMouseOver="this.src='images/icons_fontB2.gif'"
onClick="createIt('b');" alt="Bold">

<img src="images/icons_fontU.gif"
onMouseOut="this.src='images/icons_fontU.gif'"
onMouseOver="this.src='images/icons_fontU2.gif'"
onClick="createIt('u');" alt="Underline">

etc ...

</form>

===========================================

First off, is there code available out there that I can use? Otherwise
can someone let me know what I'm doing wrong here? The use of
createTextRange could be misused. Right now when I try this function I
get <b>[object]</b> if I click on and text and the bold link.

Any clues?

thnx

I've only picked pu js these past six months or so - thus I don't know
if my help is worth anything however, if I were debugging the script,
I'd first put an alert(Do1); at the begining of createIt() function to
ensure the value is being passed - I'm wondering if your newContent
variable should have Do1.value instead of Do1

Secondly... myTextRange - Can you hardcode a value for this first - then
test its result using another alert box (again in the createIt()
function) because I'm also wondering if another function you've written
and not noted above called createTextRange() has problems...

Sorry that I have no real answers for you - but those two area's are two
I'd be looking at to ensure they have their expected values...

Hope something there helps,
randelld
 
D

Dru

I'll take a look at these, thnx!

I have some working examples I've collected in the last 5 years, you can
apply bold, italic, underline, left, center, right, bulleted list, font:
family, size and color. I incluced graphics where I had them. If you're
interested I posted them here (warning: free Tripod server has annoying
popups and cookies).

mscir.tripod.com/email

Mike
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top