如何坚持我的表格选择,以便我以后可以使用它们?

时间:2017-06-28 21:38:17

标签: javascript php

我有一个由3个下拉列表组成的页面:代理商网络,代理商名称和客户名称。当用户选择网络时,它将在查询中用于创建代理商下拉列表。当用户选择代理时,它将用于查询以创建客户下拉列表。由于我前几天收到的一些帮助,创建下拉列表似乎工作正常。我现在的问题是持续选择,以便我可以根据网络,代理商和客户创建查询。

这是我目前的代码。

   if (!isset($_POST['network'])){
    echo "Form error";
   } else
   {
   $message = "form was successfully submitted";
   //echo "{$message} <br />";   
   $network = $_POST['network'];
   // echo "<br /> the network is :{$network}";
   // echo "<br />";

   }
   ?>
   <?php
   //**********************************************
   // query DB for NETWORK list
   //**********************************************
   $net = "";
   $agency = "";
   $query = "SELECT network_id, network_code FROM pps_agency_network";
   $result = mysqli_query($connection, $query);
   // create the html for the drop down menu for NETWORK

   echo "<body>";
   echo "<div id='network_name' class='col-md-3'>";
   echo "<h2> Agency Network </h2>";
   echo "<form action='droplistpop6b.php' method='post'>";
   echo "<select name='network'>";
   echo '<option value="*">ALL</option>';
   while($result1 = mysqli_fetch_assoc($result)) {
   // Populate the network dropdown list    

              unset($network_id, $network_name);
              $network_id = $result1['network_id'];
              $network_name = $result1['network_code']; 
              echo $network_name;
              echo '<option 
   value="'.$network_id.'">'.$network_name.'</option>';
   }
   echo "</select>";

   // send the value that was selected from the dropdown list
   echo "<input name='submit' type='submit' value='Send' />";
   //echo "</form>";
   echo "</div>";

   if(!isset($_POST['network'])){
    //echo "network key was not set <br />";
    } else  {   

    $net = $_POST['network'];
    ?>

$ net变量包含为网络选择的值。在下面的代码片段中,我尝试将此值保存到Javascript中的本地存储。但是,它似乎没有工作

   <script>
    // ADDED JAVASCRIPT TO SAVE TO LOCAL STORAGE
    window.onload = function() {
    var net = "<?php echo $net ?>"; // "A string here"  
    if (localStorage) {

            // Save the contents of net in locaStorage
            localStorage.setItem('net', net);
            alert("net is" + net);

        });
      else {
        // local storage not supported
        alert "local storage not supported";
       }
      }
      </script>

0 个答案:

没有答案