0

I'm stuck on a little thing.

I've got two select drop-down boxes inside one form.but now when I select the year and then the month I lose the selected year, I know why I lose the year. because I have set in the script onChange to javascript:document.location I've tried to put the $_GET['jaartal']; inside but it's not working.

Can somebody please help me on this issue?

This is the script.

<?php   
    //Including config and connection file
    include_once '..\config\config.php';
    include_once '..\config\inc_connect.php';

    //Retrive month value from url and put in variable
    $maand = ViewDatumArray();

    //Retrive typ value from url and put in variable
    $verwerking = $_GET['type'];
    $vast_verwerking = $verwerking;

    // Years range setup
    //$kayako_start = 2012;

    ?>
  <!DOCTYPE html PUBLIC "XHTML 1.0 Transitional" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
      <script type="text/javascript" src="../config/function.js"></script>
      <link rel="stylesheet" href="../config/style.css" type="text/css">
  </head>
  <body style="background-color:#F8F4EB">
    <div style="width:900px; margin:0px auto;">
        <input type="button" value="Ga Terug" class="goBackJS" onClick="goBack()"/>
        <br/>
        <!-- 02-01-2013 Added function for year instead -->
        <span>Kies de Jaar / Maand van overzicht dat je wilt downloaden.</span>
            <form action="" method="post">
                <select class="dropstyle" name="jaartal" onChange"<?php $jaar_keuze = $jaar?>">
                    <option value="2012" selected>Kies jaartal</option>
                <?php // Generate the years from start kayako until now.
                    foreach (range($jaar_nummer = date("Y"), 2012) as $jaar) { ?>
                    <option value="<?php echo($jaar); ?>" selected><?php echo($jaar); ?></option>
                <?php
                } 
                ?>
                </select>
            </form>

            <?php echo $jaar_keuze; ?>
            <form action="" method="post">
                <select class="dropstyle" name="maand" onChange="javascript:document.location='class.View_Evident_Download.php?type=<?php echo $vast_verwerking; ?>&jaar=<?php $_GET['jaartal']; ?>&maand=' + this.value">
                <?php
                    foreach ($maand_teksten as $keyvalue => $waarde) { ?>
                    <option value="<?php echo $keyvalue; ?>"><?php echo $waarde;?></option>
                <?php 
                } 
                ?>
                </select>
            </form>
    <?php

                if(!empty($maand)){
                    $maand_gekozen = $maand[0]; 

        //Functies voor eerste en laatste dag van de maand
        $jaardag = eersteDagVanMaand();
        $jaareind = laatsteDagVanMaand();

    echo "<br/>";
    if ($maand_gekozen < "1"){
    echo "Kies maand om te downloaden.";
    } else {
        if(isset($_GET['type']))
        {
            $type_download = $_GET['type'];
            $jaar_nummer = $_GET['jaartal'];
            echo $type_contract[$type_download] . ' van <b>' . $maand_teksten[$maand_gekozen] . $jaar_keuze . '</b> staat klaar om gedownload te worden.<br/>';
            echo '<input style="width:300px;" type="button" onClick="location.href = \'class.Controller_Evident_Download.php?type=' . $type_download . '&maand=' . $maand_gekozen . '&jaar=' . $jaar_gekozen . '\';" class="goBackJS" value="Download ' . $type_contract[$type_download] . '"';
        };
    }
    echo "<br/>";
    echo "<br/>";
    }

    ?>
<br/>
</div>
 </body>
  </html>
Patrick Stel
  • 49
  • 1
  • 8
  • 2
    Slightly confused. You are passing `jaartal` to the page right? You cannot pull this value from your current form unless you submit it. – War10ck Jan 02 '13 at 14:50
  • PHP is server-side, if the user submits something the page have got to refresh to send the request to the server so the PHP code will be executed –  Jan 02 '13 at 14:56
  • You need to put the "selected" in the select html tag according to the matching GET-Parameter, if it is set, to maintain the year info. – Adder Jan 02 '13 at 14:58

1 Answers1

3

You should after form submit set selected option as selected by adding "selected" attribute to it instead of "2012" option like you do now. You can do it like this:

<option <?php if($jaar==$_GET['jaartal']) print 'selected'; ?> value="<?php echo($jaar); ?>"><?php echo($jaar); ?></option>

To use that you should remove "selected" attribute from "2012" option. EDIT: Your other problem is this that when doing page redirect you are trying to use form data but it is not available or not same as selected value. Instead of $_GET['jaartal'] you should use javascript code that takes currently selected year. Here are some tips how to do it.

Community
  • 1
  • 1
Valdars
  • 833
  • 6
  • 9
  • I've changed to code to you're code but it still isn't placing the year number in the url. also removed the selected from 2012 – Patrick Stel Jan 02 '13 at 15:04
  • You mean when the drop down box is being used javascript should put it in a var and put that var in the url ? cause javascript is client side? – Patrick Stel Jan 02 '13 at 15:13
  • Yes. You should use javascript to take value of currently selected "jaartal" option value and put it in url. – Valdars Jan 02 '13 at 15:15