View Full Version : Javascript: Inserting text into a textarea using lists

01-04-2007, 07:38 AM
I know this question has been answered but not exactly in this fashion. I am trying to create a simple form edit function using my primitive phpbb skills. My issue is when using a list( <select> ) IE dosn't insert the text i want into the text area. the code I'm using is:

Javascript:(called by my header function)
<script type="text/javascript">
//add bbcode
function addbb(items) {
doc_content = document.form.content.value + items
document.form.content.value = doc_content

and used in:
<select >
<option onClick="javascript:addbb('TEXT HERE')"><font color='#CCCCCC'>grey</font></option>
<option onClick="javascript:addbb('TEXT HERE')"><font color='#FF0000'>red</font></option>
<option onClick="javascript:addbb('TEXT HERE')"><font color='#00FF00'>green</font></option>
<option onClick="javascript:addbb('TEXT HERE')"><font color='#0000FF'>blue</font></option>
<option onClick="javascript:addbb('TEXT HERE')"><font color='#FFFF00'>yellow</font></option>
<option onClick="javascript:addbb('TEXT HERE')"><font color='#00FFFF'>teal</font></option>
<option onClick="javascript:addbb('TEXT HERE')"><font color='#FF00FF'>purple</font></option>

I know the javascript works because i have a few buttons that call the same function but for some reason IE wont work with this. I works in firefox however I also need this to be IE compatible.

if anyone could help i would greatly appreciate it:confused:

01-04-2007, 09:31 AM
You should use onchange handling the select control, not the onclick handling the option element. IE has a bug, does not allow onclick as a native option's event. I am not very sure what you have in mind, but maybe this will do the job:

<select onchange="this.form['content'].value+=this.value">
<option value="TEXT HERE">grey</option>
<option value="TEXT HERE">red</option>

01-04-2007, 06:32 PM
this was exactly what i was looking for thanks.