View Full Version : stupid drop down menu

02-26-2003, 01:12 PM
Hi guys!

What I need must be quiet simple but I can't make it work.

I've got a text area and some buttons surrounding it. When you click on a button, "some text" is added to the textarea using the following script: (example for one button)

<script language="javascript" type="text/javascript">
function email()
var text=document.formname.textareaname.value
document.formname.textareaname.value=text + "my email is:";

What I'm trying to do now is to put a drop down menu with which you can add more "text" by selecting the options.

For example if you select "my country is" from the drop down menu, "my country is" is added to the textarea so that way you can write your country, in the final textarea would be:

bla bla bla bla bla my country is here or there bla bla bla

same if you select "my birthday is on the", "my favourite...", etc, etc, etc...

Thanks in advance.

02-26-2003, 07:30 PM
I have uploaded a file in which you can test what I mean if you want. Thanks.

02-26-2003, 07:38 PM
Im not entirely sure exactly what you want but this might be it:

<select name="list">
<option value="my country is">Country</option>
<option value="my favourite is">Favourite</option>

This is the drop down list containing the various texts

Then this is the code that adds the right text to the area:

var text=document.formname.textareaname.value
document.formname.textareaname.value=text +

This adds the value of the selected option to the end of the message as opposed to a fixed text.

Hope this helps

02-26-2003, 08:01 PM
It seems logic what you say, but I made the changes and it isn't working yet.

var text=document.myform.comments.value
document.myform.comments.value=text +

<p align="center"><select name="list">
<option selected>Add detail</option>
<option value="My Country is ">Country</option>
<option value="My favourite pet is ">Favourite</option>

What am I doing wrong?

02-26-2003, 08:14 PM
I am a little rusty on accessing select options is javascript.
I will go check that my code is correct and get back to you

02-26-2003, 08:26 PM
is a sample of code pulled straight from a javascript tutorial on combo boxes.


according to the previous code, this should work. Exactly what error codes are you receiving? else what is going wrong?

02-26-2003, 08:26 PM
thanks optimism_, I appreciate your taking the time.

02-26-2003, 08:28 PM
no problem

02-26-2003, 10:55 PM
Sorry man! I think we posted at the same time. No, I couldn't make it work. Check it out in the new attached file. We should get the same action by selecting an option of the drop-down menu than the one we get when we press the buttons. I don't have any clue.

02-26-2003, 11:10 PM
Here ya go. It seems that javascript is highly case sensitive (never knew that before) . Anyway the script is now working but i seem to have made all instances of MYFORM and COMMENTS as lowercase. Feel free to change this back if you need (just make sure you change all instances!)


ps ive saved it as txt, just rename to .htm(l)

02-26-2003, 11:29 PM
??? Anyway... It definitively works! I wouldn't have changed them to lower in my life. It is the first time I see that. Now I cannot understand why my pages look that good (because the code is usually an upper-lower-over_spaced nightmare...). Thanks a million Optimism_. Now I just have to find a use for all this.

02-26-2003, 11:31 PM

The other thing, now i think of it, was that there wasnt actually a function for the select box, so changing it wouldnt have done a thing, and also, because the code wasnt in a function, it was being called before the COMMENTS box was being created, thus an error about it not existing.

Anyway - glad it works :)