Title: adding simple drop-down
Last modified: August 31, 2016

---

# adding simple drop-down

 *  Resolved [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/)
 * I have worked on this for hours and I cannot spend any more time on this.
 * It should be simple – add a drop down and based on the value, open a URL. This
   will be in a div in header.pbp.
 * No, I do not want a custom menu, I do not want to store anything in a database,
   this is just a simple drop-down. Here is the code I have so far which is not 
   even close to working.
 *     ```
       <?php
       $taskOption = isset($_POST["company"]) ? $_POST["company"] : "";
       $handle = fopen($taskOption)
       ?>
   
       <form>
       <select id="company" name="company">
       <option <?php if ($company == 1 ) $handle = @fopen("http://www.apple.com/","rb"); ?> value="1">Apple</option>
       <option <?php if ($company == 2 ) $handle = @fopen("http://www.google.com/","rb"); ?> value="2">Samsung</option>
       <option <?php if ($company == 3 ) $handle = @fopen("http://www.htc.com/","rb"); ?> value="3">HTC</option>
       </select>
       <input type="submit" value="Submit the form"/>
       </form>
       ```
   
 * Thank you,
    Phil Persson

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

 *  [neotechnomad](https://wordpress.org/support/users/neotechnomad/)
 * (@neotechnomad)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954347)
 * Just asking… a “;” at the end of this, perhaps?
 * `$handle = fopen($taskOption)`
 *  Thread Starter [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954350)
 * Thank you, that is closer. Now I can see the “submit the form” button but when
   I click on it, nothing happens.
 *  [neotechnomad](https://wordpress.org/support/users/neotechnomad/)
 * (@neotechnomad)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954357)
 * Where is it submitting to?
 *  Thread Starter [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954358)
 * Keep in mind I have absolutely no idea what I am doing. I am trying to follow
   guides on the web, none of which are clear. The <select id=”company” name=”company”
   > item is a drop-down control that contains a list of companies. When someone
   clicks on a company name I need some PHP code to take the user to that web site.
   For instance, if they click on “Apple” then the browser takes them to [http://www.apple.com](http://www.apple.com).
 * I have no idea how the select or the form links up with the PHP or how the fopen
   works. I am totally lost.
 *  [neotechnomad](https://wordpress.org/support/users/neotechnomad/)
 * (@neotechnomad)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954380)
 * Try this [Update database data with submit button](http://stackoverflow.com/questions/29760338/update-database-data-with-submit-button)
   and this [submit HTML data to MySQL database using php](https://www.eduonix.com/blog/web-programming-tutorials/learn-submit-html-data-mysql-database-using-php/)
 *  Thread Starter [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954440)
 * I am not trying to write to a database nor am I trying to read from a database.
   This is what I am trying to do:
 * [http://webdesign.about.com/od/javascript/f/blfaqddredirect.htm](http://webdesign.about.com/od/javascript/f/blfaqddredirect.htm)
 * A drop down control has a list of values. When someone clicks on an item in the
   drop down, they are sent to a web site based on the URL associated with that 
   item.
 *  [neotechnomad](https://wordpress.org/support/users/neotechnomad/)
 * (@neotechnomad)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954448)
 * Just a thought… would it be easier to construct it in html and use jQuery to 
   activate it?
 *     ```
       <div id="companies">
       <h2 class="company-title">(title here)</h2>
       <ul class="company-links">
       <li><a href="http://www.apple.com/" title="Apple" target="_blank">Apple</a></li>
       <li><a href="http://www.google.com/" title="Google" target="_blank">Google</a></li>
       <li><a href="http://www.htc.com/" title="HTC" target="_blank">HTC</a></li>
       </ul>
       </div>
       ```
   
 *     ```
       <script>
       jQuery.noConflict()
       (function($){
   
       	$(document).ready(function() {
   
       // Company Links
   
       		$('.company-links').hide();
   
       		$('h2.company-title').click(function() {
       			$(this).next('.company-links').slideToggle(800,'swing');
       		});
   
       	});
   
       })(jQuery);
       </script>
       ```
   
 * Also, it could be easily styled in css.
 *  Thread Starter [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954476)
 * I will put that code inside header.pbp and see if it works. Thanks!
 *  Thread Starter [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954477)
 * I found an article that claimed this might work. I just want to verify that whatever
   I use will work in header.php
 *     ```
       <select name="menu1" id="menu1">
       <option value="http://www.espn.com">ESPN</option>
       <option value="http://www.cnn.com">CNN</option>
       <option value="http://www.abcnews.com">ABC</option>
       <option value="http://www.cbsnews.com">CBS</option>
       <option value="http://www.foxnews.com">FOX</option>
       </select>
       <script type="text/javascript">
        var urlmenu = document.getElementById( 'menu1' );
        urlmenu.onchange = function() {
             window.open( this.options[ this.selectedIndex ].value );
        };
       </script>
       ```
   
 *  [neotechnomad](https://wordpress.org/support/users/neotechnomad/)
 * (@neotechnomad)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954478)
 * I would set the jQuery in the fooer, actually, because it doesn’t need to run
   until the page is loaded.
 *  Thread Starter [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954554)
 * So I put the first part in header.php and the second part in footer.php? That
   sounds very confusing. I wish I could put a comment in header.php to tell people
   to find the code in footer.php but whenever I try to add a comment to these php
   files it appears on the web page.
 *  Thread Starter [pbpersson](https://wordpress.org/support/users/pbpersson/)
 * (@pbpersson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954564)
 * NeoTechnomad – I was not able to get your solution to work, and it needs to be
   a drop-down. Eventually it will contain a list of 200 cities and based on the
   state it will be routed to different pages in this web site.
 * I was able to get the Javascript example to work in header.php.
 * Thank you! 🙂
 *  [neotechnomad](https://wordpress.org/support/users/neotechnomad/)
 * (@neotechnomad)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954576)
 * Sorry… minor adjustment…
 *     ```
       <script>
       jQuery.noConflict()
       (function($){
   
       	$(document).ready(function() {
   
       // Company Links
   
       		$('.company-links').hide();
   
       		$('#companies h2').click(function() {
       			$(this).next('.company-links').slideToggle(800,'swing');
       		});
   
       	});
   
       })(jQuery);
       </script>
       ```
   
 * It should work, because I use the same on my site. See here and scroll down to“
   tags” and click on it: [http://neotechnomad.ca/](http://neotechnomad.ca/)
 * And the jQuery script is in the footer on my site.

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

The topic ‘adding simple drop-down’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 13 replies
 * 2 participants
 * Last reply from: [neotechnomad](https://wordpress.org/support/users/neotechnomad/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/adding-simple-drop-down/#post-6954576)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
