Selected text/function question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dru

    Selected text/function question


    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="JavaS cript">
    <!--
    function createIt(Do1) {
    myTextRange = document.News.N ewsStory.create TextRange();
    var newContent = "<" + Do1 + ">" + myTextRange + "</" + Do1 + ">";

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

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

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

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

    <img src="images/icons_fontB.gif "
    onMouseOut="thi s.src='images/icons_fontB.gif '"
    onMouseOver="th is.src='images/icons_fontB2.gi f'"
    onClick="create It('b');" alt="Bold">

    <img src="images/icons_fontU.gif "
    onMouseOut="thi s.src='images/icons_fontU.gif '"
    onMouseOver="th is.src='images/icons_fontU2.gi f'"
    onClick="create It('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

  • Reply Via Newsgroup

    #2
    Re: Selected text/function question

    Dru wrote:
    [color=blue]
    > 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="JavaS cript">
    > <!--
    > function createIt(Do1) {
    > myTextRange = document.News.N ewsStory.create TextRange();
    > var newContent = "<" + Do1 + ">" + myTextRange + "</" + Do1 + ">";
    >
    > document.News.N ewsStory.value = newContent;
    > }
    > // -->
    > </script>
    >
    > <body bgcolor="White" text="Black" id="myBody">
    >
    > <form action="f_uploa d.htm" method="POST" name="News">
    >
    > <textarea cols="46" rows="10" name="NewsStory "></textarea>
    >
    > <img src="images/icons_fontB.gif "
    > onMouseOut="thi s.src='images/icons_fontB.gif '"
    > onMouseOver="th is.src='images/icons_fontB2.gi f'"
    > onClick="create It('b');" alt="Bold">
    >
    > <img src="images/icons_fontU.gif "
    > onMouseOut="thi s.src='images/icons_fontU.gif '"
    > onMouseOver="th is.src='images/icons_fontU2.gi f'"
    > onClick="create It('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
    >[/color]

    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

    Comment

    • mscir

      #3
      Re: Selected text/function question

      Dru wrote:[color=blue]
      > 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.[/color]

      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.co m/email

      Mike

      Comment

      • Dru

        #4
        Re: Selected text/function question


        I'll take a look at these, thnx!

        On Wed, 14 Apr 2004 17:43:41 -0700, mscir
        <mscir@access4l ess.com.net.org .uk> wrote:
        [color=blue]
        >Dru wrote:[color=green]
        >> 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.[/color]
        >
        >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.c om/email
        >
        >Mike[/color]

        Comment

        • mscir

          #5
          Re: Selected text/function question

          Dru wrote:
          [color=blue]
          > I'll take a look at these, thnx!
          >
          > On Wed, 14 Apr 2004 17:43:41 -0700, mscir
          > <mscir@access4l ess.com.net.org .uk> wrote:[/color]

          I found a nice simple one here, might be worth a look if you don't have
          something you like working yet:



          scroll down near the bottom of the page:

          Example 2

          The second example is a simple rich text editing page, where text can be
          bolded/italicized/underlined, new links can be added and the color of
          text changed. The example page consists of an iframe, which will be the
          rich editing area, as well as elements for basic editing commands such
          as bold/italics/text color. Also provided is a "view source" button that
          will display the generated code in the iframe's document. The example
          can be found here.

          Mike

          Comment

          Working...