Results 1 to 5 of 5

Thread: Drop Down Menu

  1. #1
    Join Date
    Apr 2004
    Posts
    11

    Unanswered: Drop Down Menu

    hi there,

    I have created a form with a drop down menu and it works fine. I now need to create a new form that can up date the drop down menu of the other form.
    The code for the drop down menu is as follows:
    <table>
    <tr>
    <td> Type:</td>
    <td><select name="summer1">
    <option>Villa Pools</option>
    <option>Tunisia</option>
    <option>Summer Sun</option>
    <option>Cruise</option>
    <option>Just Flights Summer</option>
    <option>Ski & Snowboard</option>
    <option>Winter Sun</option>
    <option>Just Flights Winter</option>
    </select>
    <tr>
    </table>

    I need to be able to add a new option to this drop down menu.
    Any help with this would be greatly appreciated
    Catherine

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    168

    Re: Drop Down Menu

    Give us little more details like
    Are u getting this information from the database?
    If not the you have to add the new option to an array
    or if yea the you have to in sert the value to the database and then load the page. The action can be set to $PHP_SELF. So ths will load the cane page and in this itself you can perform the addinf new value task

    Hope this is clear.. If not revert back to us
    Regards
    Rajesh

    Originally posted by catherinec
    hi there,

    I have created a form with a drop down menu and it works fine. I now need to create a new form that can up date the drop down menu of the other form.
    The code for the drop down menu is as follows:
    <table>
    <tr>
    <td> Type:</td>
    <td><select name="summer1">
    <option>Villa Pools</option>
    <option>Tunisia</option>
    <option>Summer Sun</option>
    <option>Cruise</option>
    <option>Just Flights Summer</option>
    <option>Ski & Snowboard</option>
    <option>Winter Sun</option>
    <option>Just Flights Winter</option>
    </select>
    <tr>
    </table>

    I need to be able to add a new option to this drop down menu.
    Any help with this would be greatly appreciated
    Catherine

  3. #3
    Join Date
    Apr 2004
    Posts
    11
    Hi there,

    i am not getting the values from the database so i need to use an array. I am new to using PHP so any help you could give me with the code would be great as I am not the best programmer.

    Thanks
    Catherine

  4. #4
    Join Date
    Jan 2004
    Location
    India
    Posts
    168

    Thumbs up

    Check this now
    <?php
    $optionval=array(key=>value,.....); //this is the methode for an associative array you can use this kind.

    ?>
    Now you can get the value from the array
    <select name='anyname'>
    <?
    for($i=0;no of values in the array <=$i; $i++)
    {
    ?>
    <option value='<?=$optionval['key']?>'><?=$optionval['value']?></option>
    <?
    }
    ?>
    </select>

    This is the method to get the values displayed

    now to add a value to the array you have to use array_push()
    check for clearification on this function
    http://in2.php.net/manual/en/function.array-push.php
    So when u add something like from a text field by clicking the button you have to call this function on the top of the page and then you could add this to the array.
    The as a usual process you can fetch it into the drop down as from the code above.

    Hope this would be clear..
    Every things cannot be readymade.. so try work out a little..
    Refere the site

    Regards

    Rajesh


    Originally posted by catherinec
    Hi there,

    i am not getting the values from the database so i need to use an array. I am new to using PHP so any help you could give me with the code would be great as I am not the best programmer.

    Thanks
    Catherine

  5. #5
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    Hi Catherine

    Here is a modified extract from a function I wrote to potentially help with your situation. First you need populate an associative array with your values. I do mine from a database, but you could do this manually.

    Something like this:

    Code:
    <?php
    // populate array e.g.
    $arr_values("key_1" => "option_1"
                     ,"key_2" => "option_2"
                     ,"key_3" => "option_3"
                     ,"key_4" => "option_4"
                     );
    
    // your code modified
    <table>
    <tr> 
      <td> Type:</td>
      <td><select name="summer1">
        foreach ($arr_values as $key => $value){
        ?><option value="<?php echo $key; ?>"><?php echo $value;?></option><?php
        }</select>
      </td> 
    <tr> 
    </table>
    You can then add or remove items from the array or populate the array form a database. If you are not using option values in your select, just drop the key part of the code and make a simple array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •