#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    How to retain dropdown value on page load


    i have 3 dropdowns that filter data n dsplay in the report

    every thing is working fine but the dropdown is loaded after selecting data and the selected value get lost on page.. how to retain the value on page load as i using a JS to pass value from one dropdown to another

    PHP Code:
    <form>

          INSTITUTE:<select name="institute" onChange="MM_jumpMenu('parent',this,0)">
            
            <?php
            
            $sql
    ="select * from institute";
            
    $result=mysql_query($sql);
            
    //$abc=1;
            
    while($data=mysql_fetch_array($result,MYSQL_ASSOC))
            { 
            
    $select="";
            if(
    $data['instituteID']==$_GET['instituteID']) $select='selected="selected"';
            print 
    '<option value="?insID='.$data['instituteID'].'" '.$select.'>'." ".$data['name'].'</option>';
            }
            
    $ins=$_GET['insID'];
            
            
    ?>
          </select>
        <!--<input type=button value="Mark Attendance" onClick="take_snapshot()">-->
        <form>
          EMPLOYEE: <select name="employee" onChange="MM_jumpMenu('parent',this,0)">
            
    <?php
    $sql
    ="select * from emp where institute='".$_GET['insID']."'";
    $result=mysql_query($sql);
            while(
    $data=mysql_fetch_array($result,MYSQL_ASSOC))
            { 
            
    $select="";
            if(
    $data['empID']==$_GET['empID']) $select='selected="selected"';
            print 
    '<option value="?insID='.$ins.'&empID='.$data['empID'].'" '.$select.'>'." ".$data['name'].'</option>';
            
            }
            
    $emp=$_GET['empID'];
                    
    ?>
          </select>
          Month: <select name="month" id="month">
      <option value="1">January</option>
      <option value="2">February</option>
      <option value="3">March</option>
      <option value="4">April</option>
      <option value="5">May</option>
      <option value="6">June</option>
      <option value="7">July</option>
      <option value="8">August</option>
      <option value="9">September</option>
      <option value="10">October</option>
      <option value="11">November</option>
      <option value="12">December</option>
      </select>
      <input type="submit" value="Next"> 
      </form>
      <?php
    $month
    $_GET['month'];

    echo 
    $emp;
    echo 
    $ins;
    echo 
    $month;

    $query="SELECT * FROM viewdailyinouttimedetail where empID=".$emp." and EXTRACT(month FROM atndDate)=11";
    $result=mysql_query($query);
    if(
    mysql_num_rows($result)>0){
          echo 
    "<table class='display table'>";
        echo 
    "<thead> ";
        echo 
    "<tr>";
        echo 
    "<th>empId</th>";
        echo 
    "<th>Name</th>";
        echo 
    "<th>Date</th>";
        echo 
    "<th>InTime</th>";
        echo 
    "<th>Outtime</th>";
        echo 
    "</tr>"
        echo 
    "</thead>";
        while(
    $row=mysql_fetch_array($result)){
        echo 
    "<tr>";
        echo 
    "<td>".$row['empId']."</td>";    
        echo 
    "<td>".$row['name']."</td>";    
        echo 
    "<td>".$row['atndDate']."</td>";
        echo 
    "<td>".$row['InTime']."</td>";
        echo 
    "<td>".$row['OutTime']."</td>";

        
        echo 
    "</tr>";
        }
        echo 
    "</table>";
        }
        
    ?>
    </tbody>
    </table>

    thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    You can add in an if/then to check your $_GET/$_POST with an isset() and have it apply a 'selected' attribute to your related option.


    EDIT: Here's an example of something similar I have done for a month drop-down. It will hold the selected value, plus this one is designed to load on current month. (To show my current month bills. )

    PHP Code:
    function escape_html($input) { 
      return 
    htmlentities($inputENT_QUOTES ENT_XHTML'utf-8'); 
    }
    for(
    $i 1$i <= 12$i++) {
      
    $current_date getdate();
      
    $selected = (isset($_POST['mo']) && $_POST['mo'] == $i) || (!isset($_POST['mo']) && $i == $current_date['mon']);
      echo 
    '        <option value="' escape_html($i)  . '"' . ($selected ' selected="selected"' '') . '>' date("F"mktime(000$i10)) . "</option>\n";

    Last edited by Triple_Nothing; December 29th, 2012 at 08:57 AM.

IMN logo majestic logo threadwatch logo seochat tools logo