button to insert character in textfield?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sebnewyork
Forum Commoner
Posts: 43
Joined: Wed Mar 17, 2004 10:20 pm

button to insert character in textfield?

Post by sebnewyork »

Hi all
When I write this message in the Post New Topic textfield, clicking on the PHP button inserts some text in the textfield.
I'm trying to figure out how to do just that.

I assume these buttons are regular forms input buttons, but I have no idea what kind of action or function is necessary to have them input something in the textfield when pressed.

Please help
?>
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

a suggestion

Post by neophyte »

Well I suggest that you look at the page source of the page on this forum that you use when replying or posting. That'd have a good start.
sebnewyork
Forum Commoner
Posts: 43
Joined: Wed Mar 17, 2004 10:20 pm

Post by sebnewyork »

thanks for the tip.
Looking at the source of the page I realize that what I wanted to do probably cannot be done with PHP but needs to be done with JavaScript. Is that true?...
Anyhow I've spent the last 2 hours sorting through all the script of that page's code to figure out what little bit of script I'm looking for. The reply form of this forum obviously offers tons of sophisticated functions, while I am only looking for a simple "insert something in the textfield by clicking on that button".
It would be nice if somebody could spare me the hours of sorting through and painstakingly deciphering it all.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You do need to use javascript. there would be nothing to stop you using PHP but it wopuld be less efficient because you'd need to send the request out to the server to add the text to your page.

Code: Select all

onClick="document.getElementById('yourFormField').value=document.getElementById('yourFormField').value+' your new text'"
Of course it would be easier to make a function that does this for you....
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

By the way don't look at the source of this page to get that because I just made it up off the top of my head. There will be a quicker way to do it using a function as I said but I hope i've pointed you in the right direction :-)
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

d11wtq points you to the right methodology to use. Like these forums all the javascript needs to do is add text to the value of the textbox (although I would use document.formname.textareaname.value). This is useful for most situations which do not deal in HTML and do not need insertions at the current cursor location.

If you need more of an "Editor" feel then this methodology doesn't work and I would recommend using an Rich Text Editor Textbox as shown in the following location http://www.kevinroth.com/rte/demo.htm

NOTE: This is probably overkill for what you require but thought I'd mention it here as it may be useful for others as well.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Thanks for the tip coder goblin. That RTE is awesome! I'll have to integrate it into some of my programs. Thanks for posting it!
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Bear in mind that the RTE is only for Javascript. I also had to update it for browser compatibilty (effectively I got moved the browser checking more to the PHP side). Also don't forget the <noscript> tags for non Javascript users.

And you are welcome, it took me ages to find when I needed it.. :wink:
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

That is way to cool. I can see intergrating something like that into my compnaies basic CMS tool and storing all that away. brillant!!!!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Post Reply