Simple Drop down List Generator Script

Started on the old forum in September 2012 · view the original in the archive · old links redirect here

1 reply · 630 views · started 14 years ago · 1 min read

2 participants
nk4mitu Newbie · 6 posts #1
<?php
    /*  formDropDown  -  create an  HTML  <SELECT>  *  vars:  $name  -  the  form  variable  NAME  *              $value  -  the  SELECTED  option  *              $labels  -  assoc.  array,  list  of  values=>labels  *  returns:  string,  HTML  (i.e.  for  use  in  echo  or  print  statement)  */ FUNCTION   formDropDown ( $name , $value , $labels ) { $html = "<SELECT  NAME= \" $name \" > \n " ; $key = KEY ( $labels ) ; WHILE ( $key != "" ) { IF ( $key == $value ) { $selected = "SELECTED" ; } ELSE { $selected = "" ; } $html .= "<OPTION  VALUE= \" $key \" $selected > $labels [ $key ] \n " ; NEXT ( $labels ) ; $key = KEY ( $labels ) ; } $html .= "</SELECT> \n " ; RETURN $html ; } 
?>

#THIS SCRIPT FOR WEBMASTERS# Please move script if i post in wrong Place!!!

arnage Lead · 811 posts #2

Or something like this? 🙂

$color_array = array(/* ... */);

echo 'Body Text Color:<br/>'."\n"; 
echo '<select name="body_text_color" title="Select Body Text Color">'."\n"; 
echo '<option value="">None</option>'."\n"; 
        foreach ($color_array as $col => $color) { 
            echo '<option value="'.$color.'"'.($usersset['bodycolor'] == $color ? ' selected="selected">' : '>').$col.'</option>'."\n"; 
        } 
echo '</select>'."\n"; 
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close