[nycphp-talk] dynamic jump menu from flatfile
Daniel Krook
danielk at us.ibm.com
Mon May 3 10:13:49 EDT 2004
>Hiya folks.. was juts sitting here wondering if there was a way to make a
>jump menu that got its info from a flat file.
Certainly is possible, try something like this...
<?php
function drawNav () {
// items.txt would look like this:
// http://ibm.com/|IBM.com
// http://google.com/|Google
$lines = file('items.txt');
$html = '<select onchange="go(this);"></select>';
foreach ($lines as $line) {
$items = explode('|', $line);
$html .= sprintf('<option value="' . $items[0] . '">' .
$items[1] . '</option>');
}
echo ($html . '</select>');
}
The JavaScript function in the select tag is:
/**
* Jumps to the selected item in the dropdown list .
*/
function go (dropdown) {
location.href =
dropdown.options[dropdown.selectedIndex].value;
}
Daniel Krook, Application Developer
WW Web Production Services North 2, ibm.com
1133 Westchester Avenue, White Plains, NY 10604
Personal: http://info.krook.org/
Persona: http://w3.ibm.com/eworkplace/persona_bp_finder.jsp?CNUM=C-0M7P897
More information about the talk
mailing list