Drop down menu
7 posts by 4 authors in: Forums > CMS Builder
Last Post: July 20, 2008 (RSS)
By Janet - July 16, 2008
What I wanted to include on my "courses" list page is a drop down menu populated by the [semester] field.
This code populates the drop down menu:
<form method="get" action="coursesList.php">
<select name="Semester">
<?php foreach ($listRows as $record): ?>
<option value="<?php echo $record['semester'] ?>"> <?php echo $record['semester'] ?> </option>
<?php endforeach ?> </form>
but I don't know how to limit the results to one (right now it lists Fall 2008 as many times as there are records) and I don't know how to tell the code to show only "Fall 2008" courses when selected, "Spring 2009" courses when selected, etc.
Can this be done?
Jan
Re: [Janet] Drop down menu
By Dave - July 17, 2008
<form method="get" action="coursesList.php">
<select name="Semester">
<?php foreach ($listRows as $record): ?>
<?php
if (@$lastSemester == $record['semester']) { continue; } // skip this one
$lastSemester = $record['semester']; // keep track of last seen semester
?>
<option value="<?php echo $record['semester'] ?>"> <?php echo $record['semester'] ?> </option>
<?php endforeach ?>
</form>
Let me know if that works for you! :)
interactivetools.com
Re: [Dave] Drop down menu
By Janet - July 17, 2008
Thanks again for your quick response. Your code worked great once I realized my mistake. I use Dreamweaver in conjunction with CMS Builder so when I created the menu I used the "List Menu" format. Time for a vacation.
Here's the snippet I ended with:
In the head tags:
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
Inside the body tag:
<select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
<option>Select Semester</option>
<?php foreach ($listRows as $record): ?>
<?php
if (@$lastSemester == $record['category_name']) { continue; } // skip this one
$lastSemester = $record['category_name']; // keep track of last seen semester
?>
<option value="coursesList.php?category=<?php echo $record['category_name'] ?>"> <?php echo $record['category_name'] ?> </option>
<?php endforeach ?>
</select>
I strayed a little from your code and set up a separate section edition for "Semesters." Next time, I'm going to try it using a list field in the article editor, your code and the right Dreamweaver code for jump menu.
This is a win-win. My client is getting a cool site, she's loving how easy it is to enter content, I'm loving how much I can customize it PLUS I think I'm learning a little PHP.
The page isn't perfect yet - I'm still tweaking but here it is: http://www.uga.edu/dev/ecology/coursesList.php?category=Fall%202008
Thanks again!
Jan
Re: [Janet] Drop down menu
By Dave - July 18, 2008
Looks great! Thanks for posting back and sharing the url with us! :)
interactivetools.com
Re: [Janet] Drop down menu
By Donna - July 18, 2008
;)
--
support@interactivetools.com
Re: [Donna] Drop down menu
By Janet - July 18, 2008
Re: [Janet] Drop down menu
By gkornbluth - July 20, 2008
And your site does look really good.
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php