Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    CPD
    CPD is offline
    New Coder
    Join Date
    Jul 2012
    Location
    Ontario Canada
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Duplicating a drop down based on the pervious drop down

    What I need to do is based on the "guest" select I need to multiply the rate selects
    PHP Code:
    <?php
        
        
    if($date != null && is_numeric($date) && $region != null && $vid != null && $sid != null)
        {
        
        
    ?>

    <tr><td>Number of Guests</td><td>
       
        
        <select name="guest" onChange="autoSubmit();">
            <option value="null">Select Guests</option>
            <option value="1" <?php if($guest == 1) echo " selected"?>>One</option>
            <option value="2" <?php if($guest == 2) echo " selected"?>>Two</option>
        <option value="3" <?php if($guest == 3) echo " selected"?>>Three</option>
        <option value="4" <?php if($guest == 4) echo " selected"?>>Four</option> 
        <option value="5" <?php if($guest == 5) echo " selected"?>>Five</option> 
        <option value="6" <?php if($guest == 6) echo " selected"?>>Six</option> 
        <option value="7" <?php if($guest == 7) echo " selected"?>>Seven</option> 
         <option value="8" <?php if($guest == 8) echo " selected"?>>Eight</option> 
     </select>

    </td><tr>


     <?php  
        

        
    ?>




    <!------This makes sure that the above selects and inputs are filled first------>

        <?php
        
        
    if($guest != null && is_numeric($guest) && $region != null && $vid != null && $sid != null && $date != null)
        {
        
        
    ?>








    <?
    $si
    =1;
    function 
    guest(){

       
    ?>
    <!------------------------------------------------------------------------------>
    <!--------This seventh select selects the SHOW RATES based on the SHOW ID------->


    <tr><td>Select Show Rates</td><td>
        <select name="rate" onChange="autoSubmit();">
            <option value="null">Select Show Rates</option>
            
            <?php
            
            $sql4 
    "SELECT * FROM vshows WHERE sid = $sid ";
            
    $rates mysql_query($sql4,$conn);
            
            while(
    $row mysql_fetch_array($rates))
            {
            echo (
    "<option value=\"$row[sratek]\" " . ($rate == $row["sratek"] ? " selected " "") . ">$row[sratek]</option>");
            echo (
    "<option value=\"$row[sratea]\" " . ($rate == $row["sratea"] ? " selected " "") . ">$row[sratea]</option>");
            echo (
    "<option value=\"$row[sratef]\" " . ($rate == $row["sratef"] ? " selected " "") . ">$row[sratef]</option>");
            echo (
    "<option value=\"$row[srateo]\" " . ($rate == $row["srateo"] ? " selected " "") . ">$row[srateo]</option>");
             echo (
    "<option value=\"$row[sratecomp]\" " . ($rate == $row["sratecomp"] ? " selected " "") . ">$row[sratecomp]</option>");        
            }

            
    ?>    
            
        </select>
    </td><tr>
        
        <?php  
        

        
    ?>
    <?
        
    if ($guest $si) {
            print 
    "Next Guest";
             
            return 
    guest() ; // restart process
        
    }
        
    $si++
    }
    ?>
    So if the "guest Select is 4, then I need to have 4 of the "rate" drop downs, and to increment the drop down name and vars by that amount
    eg.
    rate $var
    rate1 $var1
    rate2 $var2
    rate3 $var3

    So if there are 4 guests selected then
    guest 1 is an adult rate will be .......
    guest 2 is an adult rate1 will be......
    guest 3 is a senior rate 2 will be .....
    guest 4 is a child rate3 will be.......

    I tried to do a function guest as seen above but it don't work
    any thoughts ??
    Last edited by CPD; 07-28-2012 at 12:53 AM.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,187
    Thanks
    15
    Thanked 253 Times in 253 Posts
    One thing is, when you do this with php you have to reload the page unless you use something like AJAX, or another server call. You might look into doing it with javascript which doesn't need to call the server or reload the page. JS can also change the value of an input.


  •  

    Posting Permissions

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