Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    stupid drop down menu

    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.

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have uploaded a file in which you can test what I mean if you want. Thanks.
    Attached Files Attached Files

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Im not entirely sure exactly what you want but this might be it:

    Code:
    <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:
    Code:
    <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
    <?XML version="1.0" standalone="Yes" encoding="utf-8"?>
    <SIGNITURE>
    XML is the future - embrace it
    </SIGNITURE>

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #5
    New Coder
    Join Date
    Jan 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    <?XML version="1.0" standalone="Yes" encoding="utf-8"?>
    <SIGNITURE>
    XML is the future - embrace it
    </SIGNITURE>

  • #6
    New Coder
    Join Date
    Jan 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    <?XML version="1.0" standalone="Yes" encoding="utf-8"?>
    <SIGNITURE>
    XML is the future - embrace it
    </SIGNITURE>

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks optimism_, I appreciate your taking the time.

  • #8
    New Coder
    Join Date
    Jan 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no problem
    <?XML version="1.0" standalone="Yes" encoding="utf-8"?>
    <SIGNITURE>
    XML is the future - embrace it
    </SIGNITURE>

  • #9
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not yet !

    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.
    Attached Files Attached Files

  • #10
    New Coder
    Join Date
    Jan 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)
    Attached Files Attached Files
    <?XML version="1.0" standalone="Yes" encoding="utf-8"?>
    <SIGNITURE>
    XML is the future - embrace it
    </SIGNITURE>

  • #11
    Regular Coder
    Join Date
    Feb 2003
    Posts
    345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ¿?¿?¿? 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.

  • #12
    New Coder
    Join Date
    Jan 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    <?XML version="1.0" standalone="Yes" encoding="utf-8"?>
    <SIGNITURE>
    XML is the future - embrace it
    </SIGNITURE>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •