button to insert character in textfield?
Moderator: General Moderators
-
sebnewyork
- Forum Commoner
- Posts: 43
- Joined: Wed Mar 17, 2004 10:20 pm
button to insert character in textfield?
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
?>
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
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
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.
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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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.
Of course it would be easier to make a function that does this for you....
Code: Select all
onClick="document.getElementById('yourFormField').value=document.getElementById('yourFormField').value+' your new text'"- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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.
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.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
i usually use http://www.zhuo.org/htmlarea/
but i also plugin http://alrashid.klokan.sk/insFile/htmlareademo/
but i also plugin http://alrashid.klokan.sk/insFile/htmlareademo/