SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    JS: How to click an image, that creates text in a textarea

    Sorta like Vbulliten when clicking on the images, smilies, it creates "" in the textarea box. How do they do that?

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To maintain flexibility, I'd do it this way.
    Code:
    function insertText(txt, elemID) {
    	elem = document.getElementById(elemID);
    	elem.value += txt;
    	}
    	
    <form>
    <textarea id="content"></textarea>
    <input type="text" id="insert" /><input type="button" value="&#171; Insert this text" onClick="insertText(this.form.insert.value, 'content');" />
    <input type="button id="Add Smiley :)" onClick=insertText(":)", 'content');" />
    </form>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I get a syntax error

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I didn't debug it, but it was just a couple typos

    Change up the button to this
    Code:
    <input type="button" value="Add Smiley :)" onClick="insertText(':)', 'content');" />
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    works great, thanks a bunch

  6. #6
    SitePoint Addict Ghz's Avatar
    Join Date
    Jun 2002
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excuse me,
    How do I use this piece of code? Where do I put the function code and where to put the rest? I always get errors when I use this code on any how,,,

    Please help

  7. #7
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think you have to create a javascript file name something.js and put the function inside the javascript file. after that
    <head>
    <script language="JavaScript" type="text/javascript" src="1.js"></script>
    </head>
    <form>
    <textarea id="content"></textarea>
    <input type="button" value="Add Smiley " onClick="insertText('<br>', 'content');" />
    </form>
    in my code i put the function inside 1.js just do it. it will work nicely


Bookmarks

Posting Permissions

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