SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    None of the above, add extra textfield

    I have a dropdown, let's say like:
    <select name="city">
    <option value="1">amsterdam</option>
    <option value="2">london</option>
    <option value="3">paris</option>
    <option value="4">berlin</option>
    <option value="none">none of the above</option>
    </select>

    How can I achieve that if "none of the above" is selected a new textfield with the same name shows up where a new city can be filled in ?

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <style type="text/css">
    
    #other {
        visibility: hidden; 
    }
    
    </style>
    <script type="text/javascript">
    
    function select_onchange(oSelect, oText)
    {
        var selval = oSelect.options[oSelect.selectedIndex].value;
        var bWhich = (selval == 'other')
        oText.style.visibility = (bWhich) ? 'visible' : 'hidden';
        oText.disabled = !bWhich;
        if (bWhich)
             oText.focus();
    }
    
    </script>
    </head>
    <body>
    <form>
    <select name="city" onchange="return select_onchange(this,other)">
    <option value="">- choose city -</option>
    <option value="1">amsterdam</option>
    <option value="2">london</option>
    <option value="3">paris</option>
    <option value="4">berlin</option>
    <option value="other">other</option>
    </select>
    <input id="other" type="text" name="other" value="" disabled="disabled" />
    </form>
    </body>
    </html>
    ::: certified wild guess :::

  3. #3
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx, it works like a charm.
    Do you know for which browserversions it is compatible


Bookmarks

Posting Permissions

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