0

HI

I seem to have a problem with a drop down menu, the code seems to work fine and the values are showing in source code but do not show on the page????

Another issue is I dont know how to move forward after this to make a combo drop down box whereby the selected value of the first box then decides what is populated in the 2nd box and then a selection is made from there to go to that url.

Hope somebody can help.

    <head>
    <style type="text/css">
            #myForm select option:nth-child(odd) {
                color:orange;
                background:lightgray;
            }
            #myForm select option:nth-child(even) {
                color:orange;
                background:white;
    font-colour:orange;
            }
            #myForm select {
                background:gray;
                color:orange;
            }
        </style>
    </head>


    <body>
    <form id="myForm" action="#" method="get">
    <select name="select1">
    <option value="Select Option">Select Option</option>
    <?php
    $con = mysql_connect("","","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("Database", $con);
    $result=mysql_query("select * from TABLE where Field='whatever' ORDER BY whatever, whatever2");
    while($row=mysql_fetch_array($result))
    ?>
    <option value="<?php echo $row['whatever']; ?>" <?php echo $row['whatever2'];?></option>
    <?php                                                
    }   
    ?>  
    </select>
    </body>
    </html>
2
Contributors
7
Replies
8
Views
4 Years
Discussion Span
Last Post by AleMonteiro
0

You are missing the closing > for the option, ater the last " for the value.

<option value="<?php echo $row['whatever']; ?>"> <?php echo $row['whatever2'];?></option>

0

Thanks
Brilliant, that now works perfectly.

Now is it possible to help me on the other matter posted which is I dont know how to move forward after this to make a combo drop down box whereby the selected value of the first box then decides what is populated in the 2nd box and then a selection is made from there to go to that url.

0

Those are the steps that you need to take care of:

Add a listener to the change event of the select.
Once changed, send the selected value to a php page (either using form submit or AJAX)
The PHP page will read the value and query the database.
If using AJAX: The PHP page will return the options. The JS handler to the AJAX will insert the options in the select
If using form submit: The PHP page will response the whole page again. This way you have to check if there's a selected value or not in the session to either show both selects or only the first.

I may be forgotting something, but that's the basic.

Obs.: I had to remove the enumeration and format because the post validation have some kind of bug.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.