Title: Custom Form Dropdown (Add Value)
Last modified: August 22, 2016

---

# Custom Form Dropdown (Add Value)

 *  Resolved [mannyotr](https://wordpress.org/support/users/mannyotr/)
 * (@mannyotr)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/custom-form-dropdown-add-value/)
 * I have a page in a child theme with a custom HTML form.
 * One of the form fields is a dropdown box with several values.
 * I would like to have the dropdown box have an “Other…” option. Anytime this option
   is selected the user would be presented with a text field in which to manually
   enter a value that is not available on the dropdown list.
 * I have researched this and understand that it has to be done with jQuery, but
   for the life of me I can’t figure out how.
 * Please help.
 * Manny

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/custom-form-dropdown-add-value/#post-5752058)
 * Not necessarily jQuery, though that could make it easier. Good ol’ plain javascript
   will suffice. You essentially output the text field when the form is output, 
   except it is normally hidden by CSS `visibility: none;` (unless “Other…” is the
   default selection).
 * You add an event handler for the dropdown’s onchange event. The handler logic
   would be if the “Other…” option was selected, change the text field visibility
   to block or inline, else change it to none. It’s not a problem to set it to none
   even though it may have already been that way.
 *  Thread Starter [mannyotr](https://wordpress.org/support/users/mannyotr/)
 * (@mannyotr)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/custom-form-dropdown-add-value/#post-5752124)
 * Here’s what I have in my child page…
 * First, I have this script:
 *     ```
       <script language="javascript">
       function showme(){
         var s = document.race-registration-form.team_name_select;
         var h = document.race-registration-form.team_name_enter;
         if( s.selectedIndex == 5 ) {
           h.style.visibility="visible";
         } else {
           h.style.visibility="hidden";
           }
         }
       </script>
       ```
   
 * Then I have this HTML code:
 *     ```
       <select name="team_name_select" onchange="showme()">
         <option value="none">select a team name</option>
         <option value="team1">Team 1</option>
         <option value="team2">Team 2</option>
         <option value="team3">Team 3</option>
         <option value="team4">Team 4</option>
         <option value="other">Other...</option>
       </select>
       <input type ="text" name="team_name_enter" style="position:relative;visibility:hidden;" value="enter a team name">
       ```
   
 * Doesn’t seem to work on my WordPress child page.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/custom-form-dropdown-add-value/#post-5752166)
 * Hmmm. There’s a problem with using hyphens (-) in the form tag name. Switching
   to underscore solves the problem. `race_registration_form`
 * FYI I determined this by loading your script onto a pre-defined test page I have
   and checking the JS console for errors when selecting Other…
 * I’m not sure why hyphens are a problem, the console reported “ReferenceError:
   registration is not defined” when hyphens are used. No problem with race or form,
   just registration. Queer.
 *  Thread Starter [mannyotr](https://wordpress.org/support/users/mannyotr/)
 * (@mannyotr)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/custom-form-dropdown-add-value/#post-5752178)
 * Worked like a charm! Thanks for your help bc.
 * Manny

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom Form Dropdown (Add Value)’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [mannyotr](https://wordpress.org/support/users/mannyotr/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/custom-form-dropdown-add-value/#post-5752178)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
