Results 1 to 10 of 10

Thread: Adding Text/Images to Textarea *SOLVED*

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Adding Text/Images to Textarea *SOLVED*

    I posted this question

    "Not sure how to explain this so will use this forum as an example. When creating a new post or replying to an existing one if you click one of the smilies it is then added to the message being typed. I am creating a similar process but don't know how to add the smilie to the textarea once it has been clicked.

    This is the reply I got which works fine but how can I made (rolleyes) a variable so I can insert anything??
    Code:
    <html>
    <head>
    <title>
    Example - by Phreak
    </title>
    <script language="javascript">
    function addittotextarea()
    {
    form1.text1.value += ":rolleyes:";
    }
    </script>
    </head>
    <body>
    <form name="form1">
    <textarea name="text1"></textarea>
    <input type="button" onClick="addittotextarea()">
    </form>
    </body>
    </html>
    Last edited by lintz; Sep 6th, 2004 at 06:32 AM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Example - by Phreak
    Aah, see... there's your problem right there.


    Code:
    function addittotextarea()
    {
    form1.text1.value += ":something:";
    }

    Is about right.

    When you insert :something: in the textarea, it's upto the server-side script to parse that, and replace it with an actual <img> tag when it is being displayed to the user again. Do you see the difference?

  3. #3

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    I understand that part - my question was how to make ":something:" a variable so I don't have to have a seperate function to display each smilie.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    You don't need a separate function for each smilie in the first place. What are you talking about?

  5. #5

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    If I don't need a seperate function to add each smilie to the textarea then how do I use the below function to add a different smilie or is there another (better) way to do it??

    PHP Code:
    //This is an example of how my smilies are displayed
    "<img src=\"smilie1.gif\" alt=\"bigsmile\" onClick=\"addittotextarea()\">";

    //This is the function used to display the smilie in the textarea
    function addittotextarea()
    {
    form1.text1.value += ":something:";


  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Code:
    function addittotextarea(smiley)
    {
    form1.text1.value += smiley;
    }
    Then call your function with the smiley you would like to add:
    Code:
    addittotextarea(":something:");
    Is that what you mean?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Yes, I think that's what he means.

  8. #8

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Thanks Jop - that was exactly what I was tryng to do.

    I got it working!

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Modern boards are more sophisticated, though. They query the position of the cursor and insert the smiley there.

    That takes different approaches for different browsers, though.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Originally posted by mendhak
    Aah, see... there's your problem right there.
    *slap*

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width