Results 1 to 5 of 5

Thread: add text to a textbox by buttons

  1. #1
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default add text to a textbox by buttons

    Hi

    I've wondered how can I add text to a text box by clicking on button.

    What I mean is, if now the value of my text box is "hello!", after clicking the button the value will change into "hello!some-text", and by clicking it again the value will turn to "hello!some-textsome-text"

    etc.

    Thank you very much!

  2. #2
    Join Date
    Sep 2008
    Posts
    26
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    you could add a onclick= for the button with

    document.getElementById('myinput').value+="bla";

    (field+=text is the same as field=field+text.)

    Of course you must change the myinput to the id= of your textfield/area ;-)

  3. The Following User Says Thank You to schorhr For This Useful Post:

    d-machine (09-19-2008)

  4. #3
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default

    so easy but so useful

    THANK YOU VERY VERY MUCH!

  5. #4
    Join Date
    Sep 2008
    Posts
    26
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    No problem :-) I just hope everything was correct as I am just starting to (re-) learn javascript myself.

  6. #5
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    There is another way (and MANY ways) to do this.

    document.formname.textboxname.value = "jim";

    Changes the text-box value to jim.

    document.formname.textboxname.value += "jim";

    Adds the value jim into the textbox. It ADDS to it.

    You can also use the document.getElementsByTagName() function and document.getElementById() function to change the value of the textbox.

    It seems that you don't know much about programming. If you are a newbie, visit http://www.w3schools.com/ - they have AWESOME tutorials for WEB programming.

    -magicyte

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
  •