SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting drop down item enables a hidden text field

    Hi,

    I wish to provide a facility wereby a visitor can use a drop down box to tell us where they heard of us from. One of the options with be an "Other" option which when selected will show a text field for them to enter the other place they heard of us from.

    How can I do this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    London, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a rough sketch that you can work from:
    Code:
    <select name="foo" id="selectfoo"
     onchange="if (this.options[this.selectedIndex].value=='other'){enableExtrafield('selectfoo')}">
     <option value="google">Google</option>
     <option value="other">Other</option>
    </select>
    Code:
    <script>
    function enableExtrafield(select_id) {
      var select_node = document.getElementById(select_id);
      var new_node = document.createElement('input');
      new_node.setAttribute('name','foo_other');
      new_node.setAttribute('value','Please specify...');
      select_node.parentNode.insertBefore(new_node, select_node);
    }
    </script>
    That should get you started. Good luck!


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
  •