PDA

View Full Version : Auto Submit - HTML Drop Down Menu


llbbl
02-14-2005, 02:41 PM
I think the only way is to use a java. I haven't found a good guide that shows how to do it online. Let me know if you find one. Here is some information that I found that relates to it.

http://www.webbasedprogramming.com/Java-1.2-Unleashed/ch09.htm

http://www.upenn.edu/computing/web/webdev/gotomenu.html

llbbl
02-14-2005, 02:43 PM
We do it on our site in the blue bar at the bottom of each review. It is a drop menu called QuickNav.

http://reviews.designtechnica.com/

llbbl
02-14-2005, 02:46 PM
Ya ok I figured it out :P

Here is an example.

<select name="quicknav" OnChange="location.href=this.options[this.selectedIndex].value">
<option value="review2298.html">-- Choose a Page --</option>
<option value="review2298_intro11497.html">Summary</option><option value="review2298_main11498.html">Full Review: Page 1</option><option value="review2298_main11498_page2.html">Full Review: Page 2</option><option value="review2298_main11498_page3.html">Full Review: Page 3</option><option value="review2298_specs11499.html">Specs</option><option value="user_reviews2298.html">User Reviews</option></select>

k2
02-15-2005, 11:24 AM
i verify the value before changing location, like this.

Goto = function (itObj) {
if (itObj != ""){
nIndex = itObj.selectedIndex;
if(itObj.options[nIndex].value != "") { window.location = itObj.options[nIndex].value; }
else { itObj.options[0].selected = true; }
}
}

and just use an OnChange="Goto(this);" on the select box. that way you can have well, a title in the select, empty space .. or whatever. to make it work in all browsers, you need to value="" on the empty selects instead of leaving it out (oldschool ie trick).

llbbl
03-18-2005, 06:37 AM
Bah you don't need a title in the drop down menu. ;) I just use text next to the menu to describe it.

I pull the size of the menu from a database query. Load that into a variable. Then I have my <select name=url ... > as above. I find the size of the variable and loop through it building the URL dynamically echoing it.

If you need to store the value of what you selected in the menu and pass this back as a form element, than use a <input type=hidden ... > tag

k2
03-18-2005, 07:18 AM
that js function works with what you do, except it pulls the location out of the select box and into a function, which you can reuse for different purposes / select box options.

llbbl
03-23-2005, 10:48 AM
well i have to loop through the variable anyways and it is not like it is much more work to add the code to find if the file is selected or not.


echo "<select name=\"test\" OnChange=\"location.href=this.options[this.selectedIndex].value\">\n";
$l = "";
$f = 0;
$c = sizeof($list);

for ($i = 0; $i < $c; $i++) {

$clist = $list[$i];
$url = "/PATH/page.php?a=do&b=$b";

if (strcmp($clist, $b) == 0) {
echo "<option value=\"$url\" selected>";
$f= 1;
} else
echo "<option value=\"$url\">";

if (empty($l))
echo $clist;
else
echo $l[$i];

echo "</option>\n";
}

echo "</select>\n";



That's what it looks like in PHP. $a is the variable of stuff I want to put in the menu and $b is the thing that is selected. $url is link to the same page with the variable $b in the url.