Page 1 of 1

Trouble with a listbox displaying twice

Posted: Sun Apr 26, 2009 7:14 pm
by Burton333
I am trying to create a page that allows the user to create a schedule of classes. I have created a form that allows the user to do one of two things: 1. They can choose to just enter a unique class number assigned to each individual class(CRN Number) or 2. They can choose a department from a list box, which would then display a list box of the classes offered in that department that can be chosen. However for some reason I can not figure out how to stop it from displaying the department list box twice. It should only create the class list box and display that once the button "Choose" is clicked. However, when I choose a department and click choose it displays 2 department list boxes and the class list box as well. Can someone please help me out? The two list boxes are contained in "deptListBox.inc" and "classListBox.inc". Here is the code:

Code: Select all

<?php
session_start();
//files to connect to database
include("db.inc");
include("error.inc");
include("mydb.inc");
 
include ("validation_functions.php");
 
$userName= getenv('REMOTE_USER');
 
$formValid=true;
 
//intialize all form variables to defaults
$deptID=0;
$classID=0;
$compNum="";
 
//reset form variables to value passed in
if(isset($_POST['lstDepts'])) $deptID=$_POST['lstDepts'];
if(isset($_POST['lstClass'])) $classID=$_POST['lstClass'];
if(isset($_POST['txtCRNNumber'])) $compNum=$_POST['txtCRNNumber'];
 
if(isset($_POST['butChoose']))
{
  $session['deptNum'];
    $_SESSION['deptNum']=$deptID;
}   
else
if(isset($_POST['butSubmit']))
{
  //Do insert Here
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>UVM Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="menu.css" />
 
</head>
<body>
<div id="uvmImage">
<img src="uvm.gif" alt="University of Vermont" height=72px width=174px/>
</div>
<div id="menu">
        <ul>
 
            <li><a href="https://www.uvm.edu/~tlia/cs148/final/main/main.php" title="Home">Home</a></li>
            <li><a href="https://www.uvm.edu/~tlia/cs148/final/main/capacity.php" title="Class Capacity">Check Class Capacity</a></li>
            <li><a href="https://www.uvm.edu/~tlia/cs148/final/main/addClass.php" title="Add Class">Add a Class</a></li>
            <li><a href="https://www.uvm.edu/~tlia/cs148/final/main/dropClass.php" title="Drop Class">Drop a Class</a></li>
            <li><a href="https://www.uvm.edu/~tlia/cs148/final/main/changeEmail.php" title="Change Email">Change Email</a></li>
            <li><a href="https://www.uvm.edu/~tlia/cs148/final/main/dropAll.php" title="Drop All">Drop All Classes</a></li> 
        </ul>
</div>
<div id="header">
<h1>Add A Class</h1>
</div>
<div id="content">
<form action="" 
            method="post"
            id="frmRegister"
            enctype="multipart/form-data"
            onsubmit="return fblnVerified(this)">
            
            
<fieldset class="wrapper">
  <legend>Complete one field to add a class</legend>
 
<fieldset class="listBox">      
 
    <legend>Choose a department &amp then a class</legend>
        
        <?php include ("deptListBox.inc"); 
                    if(isset($_POST['lstDepts']))
                                    include ("classListBox.inc");
        ?>
        
        <input type="submit" id="butChoose" name="butChoose" value="Choose" 
                tabindex="1" class="button" />
 
</fieldset>
 
<fieldset class="crnNum">
 
                    <legend>Or enter</legend>
 
                    <label for="txtCRNNumber" class="required">CRN Number</label>
                    <input type="text" id="txtCRNNumber" name="txtCRNNumber" tabindex="2"
                    size="20" maxlength="5" onfocus="this.select()" value=''
</fieldset>
<br />
 
    <legend></legend>               
    <input type="submit" id="butSubmit" name="butSubmit" value="Submit" 
                tabindex="2" class="button" />
 
    <input type="reset" id="butReset" name="butReset" value="Reset Form" 
                tabindex="3" class="button" onclick="reSetForm()" />                
 
</fieldset>
</form>
</div>
 
</body>
</html>

Re: Trouble with a listbox displaying twice

Posted: Sun Apr 26, 2009 7:44 pm
by McInfo
  1. Incomplete & on line 74.
  2. Unclosed input tag on line 92.
  3. The double department list box problem is probably due to a condition in deptListBox.inc.
Edit: This post was recovered from search engine cache.

Re: Trouble with a listbox displaying twice

Posted: Sun Apr 26, 2009 8:03 pm
by Burton333
I am not sure what could be wrong in deptListBox.inc I have tried changing a few things, but have not figured it out yet. The code in that file looks like this:

Code: Select all

<? 
// ############################################################################
// displays a list box with all the assignments
 
//build list box of all assignments
$query = "SELECT *";
$query .= " FROM tblDept";
$query .= " WHERE pkDeptID > 0;"; 
 
include("connect.inc");
 
if ($myDatabase->numRows($query)>0){
    $deptName = $myDatabase->select($query);
 
    $display .= "<select id='lstDepts' name='lstDepts' tabindex='281' size='1'>";
     foreach($deptName as $row) {
          $display .=  "                <option value='" . $row['pkDeptID'] . "' ";
 
         if($row['pkDeptID']==$deptID){
             $display .=  "selected='selected'";
         }
 
         $display .=  ">"  . $row['fldDeptName'] . "</option>";
      }
     $display .=  "</select>";
} else {
        $display = "<p>Sorry we are unable to display this page at this time</p>";
}
 
print $display;
?>

Re: Trouble with a listbox displaying twice

Posted: Sun Apr 26, 2009 9:44 pm
by McInfo
On line 15:
Burton333 wrote:

Code: Select all

$display .= "<select id='lstDepts' name='lstDepts' tabindex='281' size='1'>";
Instead of concatenating, initialize $display as shown here.

Code: Select all

$display = "<select id='lstDepts' name='lstDepts' tabindex='281' size='1'>";
Before line 15 in deptListBox.inc, $display is assumed to be empty. After deptListBox.inc completes its tasks, $display contains a string with the select box in it. $display will continue to contain the string, even in classListBox.inc. If classListBox.inc has similar code that adds on to $display without reinitializing it, the string will just get longer.

Edit: This post was recovered from search engine cache.