Daniel Burgner
Daniel Burgner

Reputation: 224

How to tell which selectbox has a changed value using PHP?

I have two selectboxes on a web page. One displays a monthly report while another displays an archived monthly report. I would like to set a value to "Current" or "Archived" based on which selectbox is used. This is what I have done to this point.

<script>
    $(document).ready(function(){
        $('#sMonth').change(function(){
            <?php $viewType = 'Current'; ?>
        }).change();
        $('#sReportURL').change(function(){
            <?php $viewType = 'Archived'; ?>
        }).change();
    });
</script>

When I load the page, the value I want does not appear on the web page. Is there something I am missing to get this value to appear?

Upvotes: 0

Views: 65

Answers (1)

andrew
andrew

Reputation: 9583

Use ajax:

<div id="report">
</div>

and mod the script like this:

 $(document).ready(function(){
        $('#sMonth').change(function(){
            $('#report').load('report.php?viewType=current');
        });
        $('#sReportURL').change(function(){
            $('#report').load('report.php?viewType=archived');
        });
    });

and report.php:

$viewType = filter_input(INPUT_GET, 'viewType');

if($viewType == 'archived'){
echo $archivedReport;
}else{
echo $currentReport;
}

Upvotes: 1

Related Questions