PDA

View Full Version : add text to a textbox by buttons



d-machine
09-19-2008, 10:40 AM
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! :)

schorhr
09-19-2008, 11:45 AM
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 ;-)

d-machine
09-19-2008, 02:24 PM
so easy but so useful

THANK YOU VERY VERY MUCH!

schorhr
09-19-2008, 02:27 PM
No problem :-) I just hope everything was correct as I am just starting to (re-) learn javascript myself.

magicyte
09-27-2008, 02:06 AM
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