Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Textbox question! please help!

    I was woundering how i could get it so if a user presses a button it adds text to the textbox. For example, my game has a chatroom and I want to add bold, italic, underline images so when they click on them it adds "[B],[I] or [U]" to the textbox.

    Know what i mean?

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    You mean exactly the same as on vb Code for these forums? Well, a simple "view source" on the "Post a reply" page indicates that the "B" button is calling:

    vbcode(this.form,'B','')

    which, for my guess is in either vbcode_language.js or vbcode.js - which both get included a few lines above it. Download 'em, have a look.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ... or you want to know how can this be done in Java Script?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New Coder
    Join Date
    Jul 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    yeah

    yeah in javascript, that vbcode reply does nothing for me...

    Thanks for the try though spud.

    Jason

    PS: (somthing that works exactly like clicking the smilies when posting in the forum, and it inserts the code in the textbox)

    any help appreciated

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Pretty simple actually, just altering the value property of the input or textarea elements.

    Here's an example script I just put together.

    Code:
    <script type = "text/javascript">
    function add(t)
    {
       switch(t.toLowerCase())
       {
          case 'b':
          document.f.t.value += "[.b]" + window.prompt('Enter the text you want to be bold:','') + "[./b]";
          break;
          case 'i':
          document.f.t.value += "[.i]" + window.prompt('Enter the text you want to be italic:','') + "[./i]";
          break;
          case 'u':
          document.f.t.value += "[.u]" + window.prompt('Enter the text you want to be underlined:','') + "[./u]";
          break;
       }
       return;
    }
    </script>
    That's the end of the actual JavaScript code. This uses the switch statement to check what we passed to the function. Next comes the HTML form:

    Code:
    <form name = "f">
      <input type = "button" value = "Bold" onclick = "add('b');" />
      <input type = "button" value = "Italic" onclick = "add('i');" />
      <input type = "button" value = "Underlined" onclick = "add('u');" />
      <textarea rows = "10" cols = "50" name = "t"></textarea>
    </form>
    Good luck!

    Note: I put periods inside the "tags" so the vB code wouldn't kick in. Remove those and it should work nicely.
    Moderator @ WebDeveloper.com
    Mentor @ WebXpertz.net

  • #6
    New Coder
    Join Date
    Jul 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Awesome!

    Thanks a lot, okay a few more questions if you dont mind me asking...

    When pressing the Bold button, it starts the message box with...

    "Script Prompt:" is there a way to change this caption?
    Could we also do this to the caption of the messagebox itself?

    That would be great, also, If i wanted to without a message box, how would i go about that?

    Thanks again

    Jason

  • #7
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah JavaScript puts that "script prompt" text there. There's just no way around it... Although, you could make it open a new window then by using the opener object, access the textarea within the form. You could also make it so it alters the visibility or display property of a textbox.

    If you decide you want this, I could write the script for you and upload it.
    Moderator @ WebDeveloper.com
    Mentor @ WebXpertz.net

  • #8
    New Coder
    Join Date
    Jul 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Well

    Could you possibly contact me at e-mail deleted? I would like to show you what im doing, so possibly you could have the best insight on what the best possible options are available to me...

    Else, if not possible, I would like to know also, how to insert the text without the command promt as well... (i will use the message boxes for Italic, underline, and bold, but not for smilies)

    Jason
    Last edited by Alex Vincent; 12-05-2008 at 04:13 AM. Reason: e-mail deleted at author's request

  • #9
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, I emailed you.
    Moderator @ WebDeveloper.com
    Mentor @ WebXpertz.net

  • #10
    New Coder
    Join Date
    Jul 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Alright...

    Okay not sure if you got my mail, but...

    When pressing cancel, it will display this in the textbox...

    [.b]null[./b]

    Is there a way to prevent this?

    Jason


  •  

    Posting Permissions

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