The following code displays an array (value format: aaa bbb) in a list box with the correct values but when the OK button is selected it submits the values back onto the page but fails to recognise the 2nd part of each value of the array (i.e. bbb), im sure this is down to the white space within the values of the array.
How can i get it to read the whole value (i.e. aaa bbb)?
The full document is below and it will be easier to see what im trying to get when you run it.
Any Suggestions?
Cheers
How can i get it to read the whole value (i.e. aaa bbb)?
The full document is below and it will be easier to see what im trying to get when you run it.
Code:
<html>
<script language="JavaScript">
function SelectAll(combo)
{
for (var i=0;i<combo.options.length;i++)
{
combo.options[i].selected=true;
}
}
</script>
<body><form name="form" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<?php
$CorrectArray = array("aaa bbb","ccc ddd","eee fff","ggg hhh");
echo '<select name="auswahl[]" multiple>';
foreach($CorrectArray as $ValueArray =>$Answer)
{
echo "<option value=$Answer\n>$Answer\n";
}
echo '</select><br /><br />';
?>
<input type="submit" value="OK" onclick="SelectAll(document.form.elements['auswahl[]'])">
</form>
<?php
$auswahl = $_POST["auswahl"];
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
</body></html>
Cheers