www.webdeveloper.com
Results 1 to 4 of 4

Thread: Submit value of dropdown only when the checkbox is selected.

  1. #1
    Join Date
    Feb 2011
    Posts
    43

    Submit value of dropdown only when the checkbox is selected.

    I am trying to built a system that only submit the dropdown value when the checkbox is selected.

    here are my coding so far:

    PHP Code:
    <?php

    $menu
    =$_POST['Menu'];
    $subtotal=$_POST['Subtotal'];
    $total=$_POST['Total'];
    $quantity = array(); 


    mysql_connect("127.0.0.1""root""") or die(mysql_error());
    mysql_select_db("restaurantordersystem") or die(mysql_error());

    for (
    $ii=1;$ii<=5;$ii++) { 
    $temp_name "Quantity" $ii
    $quantity[$ii] = $_POST[$temp_name]; 
    }  

    // Create a MySQL table in the selected database
    $ii 1
    foreach (
    $_POST['Menu'] as $value) { 
     
    mysql_query("INSERT INTO t1 (Menu,Quantity,Subtotal,Total) VALUES ('{$value}','{$quantity[$ii]}','{$subtotal}','{$total}')  ") or die(mysql_error()); 
    $ii++; 
     }  

    ?>

  2. #2
    Join Date
    Oct 2005
    Location
    Cambridgeshire, UK
    Posts
    191
    Do you have a sample of the form that is being submitted?

    Thanks
    BIOSTALL.com
    - Freelancing Services
    - Web Development Snippets, Hints and Tips

  3. #3
    Join Date
    Feb 2011
    Posts
    43
    Code:
    <script type="text/javascript">
    
    function changeDisplayofchicken(flag) 
    { 
      if (flag) { document.getElementById('ofchicken').disabled = false; }
           else { document.getElementById('ofchicken').disabled = true; }
    }
    
    function changeDisplayhgchicken(flag) 
    {       
      if (flag) { document.getElementById('hgchicken').disabled = false; }
           else { document.getElementById('hgchicken').disabled = true; }
    }
    
    function changeDisplaysgchicken(flag) 
    {       
      if (flag) { document.getElementById('sgchicken').disabled = false; }
           else { document.getElementById('sgchicken').disabled = true; }
    }
      
    </script>
    
    </head>
    
    <body>
    <form action="FoodAllergies.php" name="menu" id="menu" method="post" style="height: 847px; width: 1267px; background-color: #008080; margin-right: auto; margin-left: auto;" class="style5">
    
    	<div class="style4" style="height: 847px; width: 1267px;">
    
    <br /><h1 class="style2" style="height: 653px; width: 1267px;"/>
    		<span class="style15"><strong>DOLLY FRIED CHICKEN'S LIST OF MENUS</strong></span><br/>
    <br />
    
    <table border="1" class="style3" align="left">
    <tr>
    <th>&nbsp;</th>
    <th style="width: 268px">FOOD</th>
    <th style="width: 87px">PRICE</th>
    <th style="width: 96px">QUANTITY</th>
    <th style="width: 101px">TOTAL (RM)</th>
    </tr>
    <tr>
    
    
    <td><input name="Menu[]" type="checkbox" value ="Original Fried Chicken" onclick="changeDisplayofchicken(this.checked)"/></td>
    <td class="style11" style="width: 268px; ">&nbsp;&nbsp; Original Fried Chicken (2pc) &nbsp;&nbsp;
    <input name="btnofchicken" src="http://ocw.ksu.edu.tw/file.php/249/openclipart/album/TzeenieWheenie/TzeenieWheenie_Small_blue_i_info_button.png" type="image" onclick="return myPopupofchicken()" height="20" width="20"/></td>
    <td style="width: 87px" >RM 5.00&nbsp;&nbsp;&nbsp; </td>
    	
    <td style="width: 96px" class="style10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	
    <select name="Quantity1" class="ff" id="ofchicken" disabled="disabled" style="width: 37px">
    	<option value="0">0</option>
    	<option value="1">1</option>
    	<option value="2">2</option>
    	<option value="3">3</option>  
    	<option value="4">4</option>  
    	<option value="5">5</option>
    	<option value="6">6</option>
    	<option value="7">7</option>
    	<option value="8">8</option>
    	</select></td>
    	
    <td style="width: 101px">
    <input type="text" name="Subtotal[]" id="totalofchicken" value="0.00" style="width: 70px"/></td>
    
    
    </tr>
    <tr>
    <td><input name="Menu[]" type="checkbox" value ="Honey Grill Chicken" onclick="changeDisplayhgchicken(this.checked)"/></td>
    <td style="width: 268px" class="style10">&nbsp;&nbsp; Honey Grill Chicken (4pc)&nbsp;&nbsp;
    <input name="btnhgchicken" src="http://ocw.ksu.edu.tw/file.php/249/openclipart/album/TzeenieWheenie/TzeenieWheenie_Small_blue_i_info_button.png" type="image" onclick="return myPopuphgchicken()" height="20" width="20"/>
    </td>
    <td style="width: 87px" name="PriceFood">RM 6.50&nbsp;&nbsp;&nbsp; </td>
    	
    <td style="width: 96px" class="style10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	
    <select name="Quantity2" class="ff" id="hgchicken" disabled="disabled" style="width: 37px">
    	<option value="0">0</option>
    	<option value="1">1</option>
    	<option value="2">2</option>
    	<option value="3">3</option>
    	<option value="4">4</option>
    	<option value="5">5</option>
    	<option value="6">6</option>
    	<option value="7">7</option>
    	<option value="8">8</option>
    	</select></td>
    	
    <td style="width: 101px"><input type="text" name="Subtotal[]" id="totalhgchicken" value="0.00" style="width: 70px"/></td>
    
    
    </tr>
    <tr>
    <td><input name="Menu[]" type="checkbox" value ="Spicy Grill Chicken" onclick="changeDisplaysgchicken(this.checked)"/></td>
    <td style="width: 268px" class="style10">&nbsp;&nbsp; Spicy Grill Chicken (4pc)&nbsp;&nbsp;
    <input name="btnsgchicken" src="http://ocw.ksu.edu.tw/file.php/249/openclipart/album/TzeenieWheenie/TzeenieWheenie_Small_blue_i_info_button.png" type="image"  onclick="return myPopupsgchicken()" height="20" width="20"/></td>
    <td style="width: 87px" name="price">RM 6.50&nbsp;&nbsp;&nbsp; </td>
    	
    <td style="width: 96px" class="style10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	
    <select name="Quantity3" class="ff" id="sgchicken" disabled="disabled" style="width: 37px">
    	<option value="0">0</option>
    	<option value="1">1</option>
    	<option value="2">2</option>
    	<option value="3">3</option>
    	<option value="4">4</option>
    	<option value="5">5</option>
    	<option value="6">6</option>
    	<option value="7">7</option>
    	<option value="8">8</option>
    	</select></td>
    	
    <td style="width: 101px"><input type="text" name="Subtotal" id="totalsgchicken" value="0.00" style="width: 70px"/></td>
    </tr>
    
    <tr>
    <td>&nbsp;</td>
    <td style="width: 268px">&nbsp;</td>
    <td style="width: 87px">&nbsp;</td>
    	
    <td style="width: 96px">&nbsp; TOTAL : </td>
    	
    <td style="width: 101px"><input type="text" name="totalfood" id="totalfood" value="0.00" style="width: 70px"/></td>
    </tr>
    
    </table>
    <h1 class="style13" style="height: 35px; width: 1213px;"/>
    <label id="Label1"><span class="style14"><strong>Total Amount (RM)</strong></span>
    </label><input name="Total" id="Total" type="text" value="0.00" style="width: 90px" />
    <input class="cal" name="calmenu" onclick="add()" style="width: 106px; height: 32px; color: #008080; background-color: #00FFFF; font-family: 'Times New Roman', Times, serif; font-size: large; font-weight: bold" type="button" value="Calculate" />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input class="style7" name="submenu" style="height: 32px; width: 108px; color: #008080; font-family: 'Times New Roman', Times, serif; font-size: large; font-weight: bolder; visibility: visible; background-color: #00FFFF;" type="submit" value="Next   &gt;&gt;"/></div>
    
    </form>

  4. #4
    Join Date
    Feb 2011
    Posts
    43
    The code is working just fine. But, if i put the array 5. Then, I'll need the select the first 5 checkbox or otherwise it will be error. As for my system, the user will have the right to choice whatever they want from the list of menu which are 36 menus and only the menu chosen will be in the db.
    Last edited by stepbystep; 03-06-2011 at 09:40 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles