...

View Full Version : stupid drop down menu



maltrecho
02-26-2003, 12: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:";
}
//-->
</script>

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.

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

optimism_
02-26-2003, 06: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>
...
</select>

This is the drop down list containing the various texts

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


<script>
var text=document.formname.textareaname.value
document.formname.textareaname.value=text +
document.formname.list.options[document.formname.list.selectedIndex].value;


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

Hope this helps

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

<script>
var text=document.myform.comments.value
document.myform.comments.value=text +
document.myform.list.options[document.myform.list.selectedIndex].value;
</script>

<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>
</select></p>

What am I doing wrong?

optimism_
02-26-2003, 07: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

optimism_
02-26-2003, 07:26 PM
document.George.example.
options[document.George.example.selectedIndex].value
is a sample of code pulled straight from a javascript tutorial on combo boxes.

document.myform.list.options[document.myform.list.selectedIndex].value

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

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

optimism_
02-26-2003, 07:28 PM
no problem

maltrecho
02-26-2003, 09: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.

optimism_
02-26-2003, 10: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!)

optimism_

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

maltrecho
02-26-2003, 10: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.

optimism_
02-26-2003, 10:31 PM
lol

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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum