Page 1 of 1
button to insert character in textfield?
Posted: Mon Nov 15, 2004 4:27 pm
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
?>
a suggestion
Posted: Mon Nov 15, 2004 4:34 pm
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.
Posted: Mon Nov 15, 2004 6:38 pm
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.
Posted: Tue Nov 16, 2004 4:21 am
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....
Posted: Tue Nov 16, 2004 4:22 am
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

Posted: Tue Nov 16, 2004 7:08 am
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.
Posted: Tue Nov 16, 2004 8:49 am
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!
Posted: Wed Nov 17, 2004 3:05 am
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..

Posted: Wed Nov 17, 2004 3:27 am
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!!!!
Posted: Wed Nov 17, 2004 4:47 am
by timvw