<HTML>
<HEAD>
<TITLE> <b> Select the colors you want </b> </TITLE>
</HEAD>
<BODY>
<FORM action="colortables.php" method='post'>
<p>Pick one or more of the colors: </p><br/>
<select name='bcolors[]' size=8 multiple>
<?php
$pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white' 'purple');
foreach ($pickcolors as $colors) {
printf("<option value='%s'>%s", $colors, $colors);
}
?>
</select>
<select name='tcolors[]' size=8 multiple>
<?php
$pickcolors2 = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple');
foreach ($pickcolors2 as $colors) {
printf("<option value='%s'>%s", $colors, $colors);
}
?>
</select>
<p><input type='submit' value='pick'></p>
</FORM>
</BODY>
</HTML>
所以我对 HTML 仍然比较陌生,所以请放轻松,我希望上面的代码在每个框中放置两个带有 8 种颜色选项的简单框,您可以用图片提交颜色和文本组合的乘法表式。出于某种原因,尽管无论我为文本颜色选择什么,此代码都说我没有选择任何颜色。任何帮助都会很棒
编辑:tcolors是文本颜色,bcolors是背景颜色
当你使用printf()
时,你没有关闭<option>
标签。还要修复数组中发现@Ashish的,
。
<select name='bcolors[]' size=8 multiple>
<?php
$pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple');
foreach ($pickcolors as $colors) {
echo "<option value='$colors'>$colors</option>";
}
?>
</select>
替换第二个select
也像我上面提到的一样。
看起来您可以对两个选择框使用相同的数组。
你可能会喜欢
<select name='bcolors[]' size=8 multiple>
<?php
$pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white','purple');
foreach ($pickcolors as $colors) {
echo "<option value='".$colors."'>".$colors."</option>";
}
?>
</select>
<!-- second select box with same array -->
<select name='tcolors[]' size=8 multiple>
<?php
foreach ($pickcolors as $colors) {
echo "<option value='".$colors."'>".$colors."</option>";
}
?>
</select>
第一个数组中'white' and 'purple'
之间缺少逗号 (,(
并且没有在循环中关闭选项
<HTML>
<HEAD>
<TITLE> <b> Select the colors you want </b> </TITLE>
</HEAD>
<BODY>
<FORM action="colortables.php" method='post'>
<p>Pick one or more of the colors: </p><br/>
<select name='bcolors[]' size=8 multiple>
<?php
$pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple');
foreach ($pickcolors as $colors) {
printf("<option value='%s'>%s</option>", $colors, $colors);
}
?>
</select>
<select name='tcolors[]' size=8 multiple>
<?php
$pickcolors2 = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple');
foreach ($pickcolors2 as $colors) {
printf("<option value='%s'>%s</option>", $colors, $colors);
}
?>
</select>
<p><input type='submit' value='pick'></p>
</FORM>
</BODY>
</HTML>
<select name='bcolors[]' size=8 multiple>
<?php
$pickcolors = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple');
foreach ($pickcolors as $key1=>$value1) {?>
<option value="<?php echo $value1;?>"><?php echo $value1;?></option>
<?php }
?>
</select>
<select name='tcolors[]' size=8 multiple>
<?php
$pickcolors2 = array('red', 'blue', 'green', 'yellow', 'orange', 'black', 'white', 'purple');
foreach ($pickcolors2 as $keys=>$values) {?>
<option value="<?php echo $$values;?>"><?php echo $values;?></option>
<?php }
?>
</select>
<inpu type="submit" name="submit" value="pick">