Forum Moderators: coopster
So, I already have the code written where I have a drop down menu with names in it. I want to be able to select multiple names from the drop down list and have them display in a table below the drop down menu. First off, I can't get one name to display, not to mention multiples. :p How may I accomplish this?
CODE:
<form action="select_onsites.php" method="post">
<table>
<tr>
<td width="40%">Select Onsite Participant:</td>
<td>
<select name="dropdownonsite" tabindex="4" onChange=submit()>
<option value="notset">- Select a Member -</option>
<?
//--- CREATE ONSITE MEMBER SELECT ---
$sql = "SELECT DISTINCT onsitename FROM onsite ORDER BY onsitename";
$onsitename = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($onsitename)) {
echo '<option value="' . $row['onsitename'] . '">' . $row['onsitename'] . '</option>';
}
?>
</select></td>
</tr>
<TR>
<td align="center" COLSPAN=3 BGCOLOR="#000080">Current Onsite Participants</td>
</TR>
<TR>
<td>Name</td>
<td>Firm</td>
<td>Phone</td>
</TR>
<TR>
<td>**display participant names**</td>
<td>**display participant firms**</td>
<td>**display participant phone numbers**</td>
</TR>
</TABLE>
<?php
if(isset($_POST["dropdownonsite /*the name you have in <select>"]))
$names = implode(', ', $_POST["dropdownonsite"]);//implodes an array to string separated by commas
?>
blabla
<td>Names: <?php echo $names;?></td>
Something like:
<select name="dropdownonsite" id="dropdownonsite" onkeyup="submitForm();"> Of course you have to write the function submitForm().
A more fancy variation is to use some Javascript XMLHTTPRequest magic. Basically you write a Javascript function to make a XMLHTTPRequest to a PHP script every time a name is selected/de-selected, then takes the data returned and updates the table automatically. This way doesn't cause the page to refresh every time someone selects an item from the drop down list, but is more complex to write.
Hope this helps you pointed in the right direction.