I have a function function pick ($name, $values, $defval=0, $size=0) { $check =
ID: 3533219 • Letter: I
Question
I have a function
function pick ($name, $values, $defval=0, $size=0)
{
$check = $defval;
echo "<select name="$name" size="$size"> ";
foreach ($values as $value)
echo " <option value = "$value" ".
(($value == $check) ? ' selected' : '') . "> $value </option> ";
echo "</select>";
}
Need to change this function so it would support multiple selections. For examle, if I have an array
$vals = array('1','2','3','4','5');
and call this function with this
picklist('pick4',$vals,array('2','4'),5);
need to highlight 2 and 4 in the output or any other values that I would want to pass
Explanation / Answer
here you go :
function pick ($name, $values, $defval=0, $size=0)
{
$check = $defval;
echo "<select name="$name" size="$size" multiple> ";
foreach ($values as $value)
echo " <option value = "$value" ".
(($value == $check) ? ' selected' : '') . "> $value </option> ";
echo "</select>";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.