|
|
|
| Title : |
'multiple select box' code that also keeps the options selected for you (as
opposed to clearing them like other code fragments illustrate). |
| Categories : |
PHP, HTML and PHP |
 Daevid Vincent |
| Date : |
Jul 20th 2000 |
| Grade : |
3 of 5 (graded 18 times) |
| Viewed : |
24995 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Daevid Vincent |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
This version fixes a little issue where upon first
load of the page, since the form hasn't been used, the $sel variable would
be an empty "string" and cause the 'each()' to STB. This one forces it to be
an 'array' and therefore doesn't choke.
--------------------- snip ------------------------
<HTML><HEAD><title>Using multiple select v2.1</title></HEAD>
<BODY>
<H2>Using multiple select v2.1</H2>
by <A HREF="http://daevid.com" TARGET="daevid">Daevid Vincent</A>
<?php
function inList($needle, $haystack)
{
while (list($k, $v) = each($haystack)) if ($needle == $v) return true;
return false;
}
function selectBox($size, $name, $matchArray)
{
settype($matchArray, "array"); //we have to force this because on the first pass,
this is set to string and will STB.
echo "<select multiple name='".$name."[]' size='".$size."'>\n";
for ($x = 0; $x < 5; $x++)
{
echo "\t<option value='key".$x."'";
if (inList("key".$x, $matchArray)) echo " SELECTED";
echo ">Value ".$x."\n";
}
echo "</select>";
} //selectBox()
////////////////////////////////////////////////////////////////////////
$num_selected = count($sel);
print "<P>Number of Values selected: $num_selected<p>\n";
if ($num_selected)
{
echo "<P>while list version<BR>\n";
while (list($k, $v) = each($sel))
{ echo "sel[".$k."] == ".$v."<BR>\n"; }
}
?>
<form method="post">
<?php selectBox(6,sel,$sel); ?>
<br>
<input type=submit value="Submit">
</form>
</BODY></HTML> |
|
| PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | Amazon book cover handling Categories : HTML and PHP, PHP, MySQL, Ecommerce | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | Complex paging with no resultset limit Categories : PHP, MySQL, Databases, Output Control, HTML and PHP | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | Website Engine Categories : PHP, HTML and PHP, Templates | | | Vote-Poll script that has a wrapper class that allows the user to create
multiple polls on the same page with little trouble. Categories : PHP, PHP Classes, HTML and PHP | | | Football News Aggregator Categories : PHP, Object Oriented, PHP Classes, Rich Site Summary (RSS), HTML and PHP | | | function textwrap will wrap text to any desired width using <BR>\n as the default line break.
Default wrap width is 80 columns.
Categories : Strings, HTML and PHP, PHP | | | Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance. Categories : HTML, PHP, HTML and PHP, Beginner Guides | | | PHP alternating the colors of table rows with style. Categories : PHP, HTML and PHP, CSS | | | Using select multiple with php3 Categories : HTML and PHP, PHP | | | PHP function which gets all the data from a webpage into a string, we can perform regular expression functions on that data afterwards to get our desired data.
Categories : PHP, URLs, HTML and PHP | | | phpFormGenerator for Dynamic Form Generation from MySQL Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP | |
| |
| |
|