下拉菜单- PHP从表单传递变量,但永远不会离开页面


drop down menu - PHP passing to variables from to forms but never leave the page

我被一件小事卡住了

我在一个表单中有两个选择下拉框。但现在,当我选择年份,然后那个月我失去了选择的年份,我知道我为什么失去了年份。因为我已经在脚本中设置了onChangejavascript:document.location,我试图把$_GET['jaartal'];放在里面,但它不起作用。

有谁能帮我解决这个问题吗?

这是脚本。

<?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>

您应该在表单提交后通过添加"selected"属性来设置选定选项,而不是像现在这样添加"2012"选项。你可以这样做:

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

要使用它,你应该从"2012"选项中删除"selected"属性。编辑:你的另一个问题是,当做页面重定向你试图使用表单数据,但它是不可用或不相同的选择值。而不是$_GET['jaartal'],你应该使用javascript代码,目前选择的年份。以下是一些如何做到这一点的建议。