Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays not acknowleding white space? 1

Status
Not open for further replies.

FAM

Technical User
Jan 13, 2003
345
GB
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.
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>
Any Suggestions?
Cheers
 
If the value attributes of form inputs have whitespace, those values must be inside quotes. You're not doing that.

This line:
echo "<option value=$Answer>$Answer\n";
should read something like:
echo '<option value="' . $Answer . '">' . $Answer . "\n";


It's a good idea to get into the habit of using quotes all the time.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks for the superquick response, that sorted it out.
I will remember for the future.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top