Selecting mutiple entires from a dynamic list box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
4wood
Forum Newbie
Posts: 8
Joined: Fri May 12, 2006 10:25 am

Post by 4wood »

OH no - we've run into another problem!

The DB now reads with Array in front of recipients....

How do I get the value of the individual option in the following:

<select name="mySelect[]" multiple="multiple">
...
</select>

I tried (to no avail):

document.formName.mySelect[0].options[0].value
document.formName.mySelect[].options[0].value
document.formName.mySelect[0].options[].value

Any ideas?? :?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try this and see what it does...

Code: Select all

<?php
$client_department_result = mysql_query("SELECT DISTINCT department_name FROM client_departments WHERE department_id='$department'") or die(mysql_error());

while($dept_row = mysql_fetch_array($client_department_result))
{
		$client_department = $dept_row['department_name'];
}

// Format Recipient(s) section to include multiple selections
$recipients = $_POST['recipients'];
$db_recipients = ''; //string holder for your array string
if(is_array($recipients))
{
	$counter = 0;
	$delim = ', ';
	$array_count = count($recipients);
	while($counter < $array_count)
	{
		if ($counter == $array_count - 1)
		{
			$delim = '';
		}
		
		$db_recipients .= $recipients[$counter] . $delim;
		
		$counter++;
	}
}

/*
echo "<hr>GET<PRE>"; print_r($_GET); echo "</PRE>";
echo "<hr>POST<PRE>"; print_r($_POST); echo "</PRE>";*/

// Insert new rows into the db with the survey form information            
$add_survey = "INSERT INTO reports(client_department, request_date, originator, recipients, reason, status, serial_id, comments)
						   VALUES('$client_department', '$requestDate', '$originators', '$db_recipients', '$reason', '$status', '$serialID', '$comments')";
mysql_query($add_survey) or die(mysql_error());
?>
Post Reply