Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Is this possible in HTML?

  • 23-10-2001 04:32PM
    #1
    Registered Users, Registered Users 2 Posts: 1,783 ✭✭✭


    I want to have a form with a text area and a submit button on a web page. That's the easy bit. On the page I also need buttons (or links maybe) that add bits of text to the text already in the text area.

    For instance. A user enters some text, say "Hello", and presses a button that inserts the word "World". The text area should now contain "Hello World". (Actually it would work a bit like the smiley buttons on this thing but not as complicated as the loverly vBulletin.)

    Is this possible in normal HTML or will I have to use javascript or something? I was going to use an Applet but I'm just trying to see if I would only be making things harder for myself than they need be. :)

    Thanks.


Comments

  • Closed Accounts Posts: 512 ✭✭✭beaver


    I'd say the best way would be to do it in the form (PERL or whatever...)


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Yeah you'll need Javascript for this but thankfully it's not difficult. Lets say you have a small input box for a name and a textarea to say hello. When the user clicks an image the textarea says "Hello " + name.

    All you need to do is update the value of the form to Hello + whatever was in the input text.

    Here's some code for getting the value of the input
    <script language="JavaScript">
    <!--
    var name = document.nameOfForm.name.value;
    //-->
    </script>
    

    That's when you have a <form> on your HTML page with a name="nameOfForm" attribute and an <input name="name" type="text">

    Adding that name to the textarea is simple:
    var textarea = document.nameOfForm.textArea.value;
    textarea += name;
    document.nameOfForm.textArea.value = textarea;
    

    Hope this helps.


  • Registered Users, Registered Users 2 Posts: 1,783 ✭✭✭Puck


    Jaysus thanks a million I wasn't actually expecting code samples! Brilliant!:D


  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Anything to avoid *real* work :D


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Since you mention vBulletin, there's also a code hack for it that allows you to stick vB Code in the cursor position, rather than at the end of the textarea, like the current setup and Enygma's code sample. You'll find it in the Code Hacks section on the vBulletin Community forum. I haven't tested it (yet), so I don't know about compatilibility.

    adam


  • Advertisement
Advertisement