HTML drop down lists.

Discussion in 'HTML & Website Design' started by fadetoblack22, Jul 2, 2008.

  1. #1
    Hello, I want to include a list on my site like the example below. I want it to appear at the top of the page and the bottom. However when I do this the go button does not work.

    I know why it is. It is because the list is repeated and the form names are conflicting.

    Does anyone know how I could get it to appear twice and avoid this problem?
    I don't really want to have to created two lists the same with different names.


    <form name="htmlMenu">
    
    <select name="htmlList" size="1" style="width:180px;">
    
    <option value="">Please select...</option>
    <option value="http://www.google.com">Google</option>
    
    </select>
                                                                      
    <input type="button" onClick="document.location = document.htmlMenu.htmlList.options [document.htmlMenu.htmlList.selectedIndex].value;"value="GO" style="width:50px;">
                                                                      
    </form>                                                           
                        
    Code (markup):
     
    fadetoblack22, Jul 2, 2008 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    1. Take name off of the form, its not a valid form attribute.
    2. Give each form a different id, such as id="form1" and id="form2".
    3. While I would never use javascript for something so simple to do in PHP (more accessible), just replace
    onClick="document.location = document.htmlMenu.value;"
    Code (markup):
    with

    
    onclick="document.location = document.getElementById('form1').htmlList.value;"
    Code (markup):
    Notice the lowercase onclick (just for neatness and validity, uppercase attributes are invalid xHTML). Also notice I got rid of that selected index crap, as all you need to do is get the value of the actual select.

    Then replace ('form1') with whatever the id of your first form is, each form will need a separate id.
     
    blueparukia, Jul 2, 2008 IP
  3. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Ok, thanks. I got the code from somewhere else.

    However it doesn't solved the problem.

    What I actually have is the list in a php file and I include it on the page.

    At the moment I have to have 2 files with the same content, but different ids.

    I need to use one file to be included on the same page.
     
    fadetoblack22, Jul 2, 2008 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    Well then getting it to work won't be easy, unless you just create another file...

    You will need to include both forms separately.

    I'd recommend just using a simple PHP function:

    
    <?php
    function outputForm($id,$name){
    
    return "
    	<form id='".$id."'>
    
    		<select name = '".$name."' style=\"width:180px;\">
    			<option value=\"\">Please select...</option>
    			<option value=\"http://www.google.com\">Google</option>
    		</select>
                                                                      
    		<input type=\"button\"
    		onclick=\"document.location = document.getElementById('".$id."').".$name.".value;\"
    		value=\"GO\" style=\"width:50px;\">
                                                                      
    </form>";
    } 
    ?>
    
    PHP:
    Then just echo it like this:

    <?php echo outputForm("form1","selectbox1"); ?>

    and

    <?php echo outputForm("form2","selectbox2"); ?>

    That will output the forms, both with different ids and names on the selectbox.
     
    blueparukia, Jul 2, 2008 IP
  5. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #5
    thanks for the help :)

    do you know how to include a target="_blank" in this:

    onclick="document.location = document.getElementById('form1').htmlList.value;"
     
    fadetoblack22, Jul 3, 2008 IP
  6. Possibility

    Possibility Peon

    Messages:
    350
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you're JS is inside of the href tag try this.target='_blank';
     
    Possibility, Jul 3, 2008 IP
  7. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #7
    Its inside the input tag:

    <input type="button" onclick="document.location = document.getElementById('mylist1').List1.value;"value="GO" style="width:50px;">
     
    fadetoblack22, Jul 3, 2008 IP