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 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    Seattle, WA USA
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Textbox to appear when Option in dropdown menu is clicked.

    Hi. I am making a simple form which sends an e-mail back to me... and you can select a Subject from a drop down menu, things like:

    Tip/Suggestion
    Personal Message
    Complaint

    and then there will be a
    "Other" option as well... but when you click on Other, a textbox is to appear next to the Select Box, where you can type your own Subject.

    Now, I have been trying to do stuff like naming the textbox with an ID of "MyText" and giving it a style="display:none" then on the Other option doing
    <option onSelect="MyText.style.display=''">Other</option>

    (and also tried OnClick) yet none of this works.

    Any tips?

    Thanks a lot! =)

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    New York, USA
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try onchange in the select tag,
    you'd need to determine which option is selected (selectedIndex) at that point and if it's the "other" option show the field, else hide it. I can dig up some working examples if you need more info.

    regards.

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    Seattle, WA USA
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A few examples would be very helpful... I understand what you mean, by the selectedIndex and stuff, but how can I determine which one is selected at the moment?

    Thanks!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    New York, USA
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here you go - I tweaked a function I had to suit your purposes.

    Note: this function is designed to be re-used elsewhere and it also allows you add options without worrying about messing up the code... however it requires that the 'other' option is always last. Not necessary of course - just one way to do this.

    <script language="JavaScript" type="text/javascript">
    <!--
    function getOther(sel,fld){
    fld.style.display = (sel.selectedIndex==sel.options.length-1)?"inline":"none";
    }
    //-->
    </script>
    <form>
    <select name="sel" onchange="getOther(this,this.form.oth);">
    <option>Tip/Suggestion
    <option>Personal Message
    <option>Complaint
    <option>Other
    </select>
    <input type="text" name="oth" style="display: none;">
    </form>

    hope that helps

  • #5
    New Coder
    Join Date
    Jun 2002
    Location
    Seattle, WA USA
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much!

    It works like a charm! =)

    I really REALLY appreciate your help.


  •  

    Posting Permissions

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