Pick subject from list

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Ok, I have this code:

Code: [ Select ]
<?php
    $course_set = mssql_query("SELECT * FROM SNP_Courses", $connection);
    if (!$course_set) {
        die("Database query failed: " . mssql_error());
    }
    
    while ($course = mssql_fetch_array($course_set)) {
        echo "<li><a href=\"grid.php?crs=" . urlencode($course["course_ID"]) .
            "\">{$course["course_name"]}</a></li>";
    } 
?>
</ul>
  1. <?php
  2.     $course_set = mssql_query("SELECT * FROM SNP_Courses", $connection);
  3.     if (!$course_set) {
  4.         die("Database query failed: " . mssql_error());
  5.     }
  6.     
  7.     while ($course = mssql_fetch_array($course_set)) {
  8.         echo "<li><a href=\"grid.php?crs=" . urlencode($course["course_ID"]) .
  9.             "\">{$course["course_name"]}</a></li>";
  10.     } 
  11. ?>
  12. </ul>


Based on this code, it will query my courses table, then give me a list of all courses, which is a hyperlink that allows me to load grid.php?crs="course_ID" and then the code ID. This works great; however, I really want to put this in a drop down list. I know how to create the drop down list, what I can't figure out is how to select something in the drop down list and when I hit select, it take me to grid.php?crs="course_ID"

Any suggestions?

Thanks,
Jordon
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

I think, you need javascript
somewhere inside head tags put this
Code: [ Select ]
 
<script language="javascript" type="text/javascript">
function changeit()
{
    var x = document.getElementById('show');
    var ite = x.options[x.selectedIndex].value;
    document.location.href="grid.php?crs="+ite+"";
}
</select>
 
  1.  
  2. <script language="javascript" type="text/javascript">
  3. function changeit()
  4. {
  5.     var x = document.getElementById('show');
  6.     var ite = x.options[x.selectedIndex].value;
  7.     document.location.href="grid.php?crs="+ite+"";
  8. }
  9. </select>
  10.  

and inside body put your drop down lists
Code: [ Select ]
 
Display: <select id="show" onchange="changeit();">
<option value="1">ABCD</option>
<option value="2">XYZ</option>
<option value="3">UVW</option>
</select>
 
  1.  
  2. Display: <select id="show" onchange="changeit();">
  3. <option value="1">ABCD</option>
  4. <option value="2">XYZ</option>
  5. <option value="3">UVW</option>
  6. </select>
  7.  

Take note about the id and onchange function defined in the drop down lists. They should be similar as defined in the javascript

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 117 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.