I have a dropdown list consists of addons items value. WHen the $a="Driver"; selected or submitted then a radio button should show up,asking users to select either one. One for 8th hour and the other for 16th hour. How to do this please?
the dropdown list as below:
<select name="addon">
<?php
mysql_select_db($database_bumi_conn, $bumi_conn);
$query="SELECT * FROM tbl_addons WHERE status=1";
$result=mysql_query($query)or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$a_id=$row['addOns_id'];
$a=$row['addOns'];
?>
<option value="<?php echo $a_id;?>"><?php echo $a;?></option>
<?php
}
?>
</select>
I tried something like this,
<script>
function myFunction() {
var person = prompt("Please type either 8 or 16 for 8th hour and 16th hour respectively", "Driver");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}
}
</script>
It pop up a box asking to type the abovementioned value. But how to store the value in a php variable?
MY HTML FORM
Pick up dateReturn dateAddon ItemsQuantity
months
$mm=array_map(function($val)
{
return sprintf('%02d', $val);
}, range(1, 12));
foreach($mm as $i)
{
$this_day = date('m');
$selected = '';
if (strlen($i) == 1) {
$i = '0'.$i;
if ($i == $this_day) $selected = 'selected="selected"';
} else {
if ($i == $this_day) $selected = 'selected="selected"';
}
?>
<option value="<?php echo $i;?>" <?php echo $selected;?>><?php echo $i;?></option>
<?php
}
?>
</select>
</td>
<td>
<span class="">date</span><br/>
<select name="date" class="">
<?php
$mm=array_map(function($val)
{
return sprintf('%02d', $val);
}, range(1, 31));
foreach($mm as $i)
{
$this_day = date('d');
$selected = '';
if (strlen($i) == 1) {
$i = '0'.$i;
if ($i == $this_day) $selected = 'selected="selected"';
} else {
if ($i == $this_day) $selected = 'selected="selected"';
}
?>
<option value="<?php echo $i;?>" <?php echo $selected;?>><?php echo $i;?></option>
<?php
}
?>
</select>
</td>
<td>
<span class="">year</span><br />
<select name="year" class="">
<?php
foreach(range(2014,2050) as $year)
{
$this_day = date('Y');
$selected = '';
if (strlen($i) == 1) {
$i = '0'.$i;
if ($i == $this_day) $selected = 'selected="selected"';
} else {
if ($i == $this_day) $selected = 'selected="selected"';
}
?>
<option value="<?php echo $year; ?>" <?php echo $selected;?>><?php echo $year; ?></option>
<?php
}
?>
</select>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<span class="">months</span><br />
<select name="months_2" class="">
<?php
$mm=array_map(function($val)
{
return sprintf('%02d', $val);
}, range(1, 12));
foreach($mm as $i)
{
$this_day = date('m');
$selected = '';
if (strlen($i) == 1) {
$i = '0'.$i;
if ($i == $this_day) $selected = 'selected="selected"';
} else {
if ($i == $this_day) $selected = 'selected="selected"';
}
?>
<option value="<?php echo $i;?>" <?php echo $selected;?>><?php echo $i;?></option>
<?php
}
?>
</select>
</td>
<td>
<span class="">date</span><br/>
<select name="date_2" class="">
<?php
$mm=array_map(function($val)
{
return sprintf('%02d', $val);
}, range(1, 31));
foreach($mm as $i)
{
$this_day = date('d');
$selected = '';
if (strlen($i) == 1) {
$i = '0'.$i;
if ($i == $this_day) $selected = 'selected="selected"';
} else {
if ($i == $this_day) $selected = 'selected="selected"';
}
?>
<option value="<?php echo $i;?>" <?php echo $selected;?>><?php echo $i;?></option>
<?php
}
?>
</select>
</td>
<td>
<span class="">year</span><br />
<select name="year_2" class="">
<?php
foreach(range(2014,2050) as $year)
{
$this_day = date('Y');
$selected = '';
if (strlen($i) == 1) {
$i = '0'.$i;
if ($i == $this_day) $selected = 'selected="selected"';
} else {
if ($i == $this_day) $selected = 'selected="selected"';
}
?>
<option value="<?php echo $year; ?>" <?php echo $selected;?>><?php echo $year; ?></option>
<?php
}
?>
</select>
</td>
</tr>
</table>
</td>
<td>
<select name="addon">
<?php
mysql_select_db($database_bumi_conn, $bumi_conn);
$query="SELECT * FROM tbl_addons WHERE status=1";
$result=mysql_query($query)or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$a_id=$row['addOns_id'];
$a=$row['addOns'];
?>
<option value="<?php echo $a_id;?>"><?php echo $a;?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="text" name="qty" />
</td>
<td>
<input type="hidden" name="mm_insert" value="insert_log" />
<input type="submit" name="add" value="Add"/>
</form>
</td>
</tr>
</table>
EDITED:
<script>
$('#radioButtons').hide();
$('#addon').bind('click',function()
{
var optionSelected=$('option:selected',this);
var valueSelected=this.value;
if($valueSelected=='6')
{
$('#radioButtons').show();
$("input[type='radio'][name='driver']").click(function()
{
var selected=$('input[type="radio"][name="driver"]:checked').val();
alert(selected);
});
}else
{
$('#radioButtons').hide();
}
});
</script>
EDITED according to @punitha suggestion:
<td>
<br/>
<select name="addon" id='addon' id="addon" onchange="triggerAddon(this.value)">
<?php
mysql_select_db($database_bumi_conn, $bumi_conn);
$query="SELECT * FROM tbl_addons WHERE status=1";
$result=mysql_query($query)or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$a_id=$row['addOns_id'];
$a=$row['addOns'];
?>
<option value="<?php echo $a_id;?>"><?php echo $a;?></option>
<?php
}
?>
</select>
</td>
<td>
<br/>
<div id="ageConfirmation">
<input type="radio" id='ageeig'name="driver" value="8">8th Hour
<input type="radio" id='agesix' name="driver" value="16">16th Hour
</div>
</td>
//script
<script>
function triggerAddon(AddonValue){ if($.trim(AddonValue)=="Driver"){$('#ageConfirmation').show(); } }
function validateForm(){
if($.trim($('#addon').val())=="Driver"){
if(!$('#ageeig').is(':checked') || !$('#agesix').is(':checked')) { alert("Please select either one"); }
}
}
</script>