i was just wondering if i could get the values of two different drop downs then pass it on jquery to back to php?
you see i have these two drop downs. one for the month and one for the year.the user could choose which month and year she/he would like then the display on the graph would change depending on the month and year chosen.i was able to do it for a single drop down but i can't do it on two drop downs.
<script type="text/javascript">
$(document).ready(function()
{
$("#months").change(function(event)
{
var m=$(this).val();
if( m == '00')
{
}
else if(m!='00' || m!='NULL')
{
$("#display").load('../crd_reports/month.php', {"m":m});
}
});
$("#years").change(function(event)
{
var y=$(this).val();
if( y == '10')
{
}
else if(y!='10' || y!='NULL')
{
$("#display").load('../crd_reports/month.php', {"y":y});
}
});
});
</script>
<div>
<select id="months">
<option value='00'>Month...</option>
<option value='01'>Jan</option>
<option value='02'>Feb</option>
<option value='03'>Mar</option>
<option value='04'>Apr</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>Aug</option>
<option value='09'>Sept</option>
<option value='10'>Oct</option>
<option value='11'>Nov</option>
<option value='12'>Dec</option>
</select>
<select id="years">
<?php
for($yr=10; $yr<=$year; $yr++)
{
echo "<option value='".$yr."'>".$years[$yr]."</option>";
}
?>
</select>
</div>
this is the start of my month.php
<?php
if (isset($_REQUEST['m']))
{
$m = $_REQUEST['m'];
// $y = $_REQUEST['y'];
include '../../include/dbconnect.php';
?>
You can create a function that runs on change of either dropdown, and passes in both parameters at once:
$('#months, #years').change(function(event)
{
var m=$('#months').val();
var y=$('#years').val();
// combine the conditions, so both must be valid before running
if( (m!='00' || m!='NULL') &&
(y!='10' || y!='NULL') )
{
$('#display').load('../crd_reports/month.php', {"y": y, "m": m});
// notice additional param ^^^^^^
}
}
Then in month.php
, you can grab both parameters and use them to populate your report:
<?php
// 'y' also has to be given before we continue
if ( isset($_REQUEST['m']) && isset($_REQUEST['y']) )
{
$m = $_REQUEST['m'];
$y = $_REQUEST['y'];
include '../../include/dbconnect.php';
// do something with $m and $y
}
else
{
echo 'Please provide month and year.';
}
?>
Try this
$(document).ready(function()
{
$("#months").change(function(event)
{
var m=$(this).val();
if( m == '00')
{
}
else if(m!='00' || m!='NULL')
{
$("#display").load('../crd_reports/month.php', {"m":m, "y": $("#years").val()});
}
});
$("#years").change(function(event)
{
var y=$(this).val();
if( y == '10')
{
}
else if(y!='10' || y!='NULL')
{
$("#display").load('../crd_reports/month.php', {"y":y, "m": $("#months").val()});
}
});
});