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 ++;
}
?>
Do you have a sample of the form that is being submitted?
Thanks
BIOSTALL.com
- Freelancing Services
- Web Development Snippets, Hints and Tips
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> </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; "> Original Fried Chicken (2pc)
<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 </td>
<td style="width: 96px" class="style10">
<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"> Honey Grill Chicken (4pc)
<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 </td>
<td style="width: 96px" class="style10">
<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"> Spicy Grill Chicken (4pc)
<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 </td>
<td style="width: 96px" class="style10">
<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> </td>
<td style="width: 268px"> </td>
<td style="width: 87px"> </td>
<td style="width: 96px"> 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" />
<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 >>"/></div>
</form>
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
Forum Rules
Bookmarks