• Resolved pbpersson

    (@pbpersson)


    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)
  • Just asking… a “;” at the end of this, perhaps?

    $handle = fopen($taskOption)

    Thread Starter pbpersson

    (@pbpersson)

    Thank you, that is closer. Now I can see the “submit the form” button but when I click on it, nothing happens.

    Where is it submitting to?

    Thread Starter pbpersson

    (@pbpersson)

    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.

    I have no idea how the select or the form links up with the PHP or how the fopen works. I am totally lost.

    Thread Starter pbpersson

    (@pbpersson)

    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

    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.

    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

    (@pbpersson)

    I will put that code inside header.pbp and see if it works. Thanks!

    Thread Starter pbpersson

    (@pbpersson)

    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>

    I would set the jQuery in the fooer, actually, because it doesn’t need to run until the page is loaded.

    Thread Starter pbpersson

    (@pbpersson)

    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

    (@pbpersson)

    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! 🙂

    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/

    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.