Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Is this possible in HTML?

Options
  • 23-10-2001 4:32pm
    #1
    Registered Users 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 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