0

我被一件小事困住了。

我在一个表单中有两个选择下拉框。但是现在当我选择年份然后月份时,我失去了选定的年份,我知道为什么我失去了年份。因为我已经在脚本onChange中设置了javascript: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>
4

1 回答 1

3

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

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

要使用它,您应该从“2012”选项中删除“selected”属性。编辑:您的另一个问题是,在进行页面重定向时,您正在尝试使用表单数据,但它不可用或与所选值不同。而不是$_GET['jaartal']您应该使用当前选定年份的javascript代码。这里有一些提示如何做到这一点。

于 2013-01-02T14:57:44.833 回答