Drop down menu

7 posts by 4 authors in: Forums > CMS Builder
Last Post: July 20, 2008   (RSS)

By Janet - July 16, 2008

I have created a "courses" list page (http://www.uga.edu/dev/ecology/coursesList.php). I only set up one section editor but I included a field called "semester" where I listed Fall 2008, Spring 2009, Summer 2009...etc.

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

It's not a feature of CMS Builder, no, but it can be done with a little bit of custom programming. Try adding the code in red:

<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! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Drop down menu

By Janet - July 17, 2008

Hey Dave - do you ever sleep?

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

Janet,

Looks great! Thanks for posting back and sharing the url with us! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Janet] Drop down menu

By Donna - July 18, 2008

Little known fact: Dave is actually a robot we keep chained to his desk...

;)
Donna

--
support@interactivetools.com

Re: [Donna] Drop down menu

By Janet - July 18, 2008

That not little known - everyone out here building sites using your software think you all live at your desks. You guys offer the best support on the planet.