Forum Moderators: coopster

Message Too Old, No Replies

Trying to select names from a drop down list and display them

problem is when I try to select mroe than one

         

BadGoat

7:23 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



Hi!

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>

jusdrum

7:34 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



To allow multiple selections in a drop down, you have to do the multiple parameter in the select tag.

<select name="dropdownonsite" tabindex="4" onChange="submit()" multiple="multiple">

BadGoat

7:35 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



hi jusdrum,

for the sake of inept users who will be using this, I was hoping that after each selection I make, the name, firm, and phone would be displayed in a table below the drop down menu.. Is this possible/feasible?

mcibor

7:40 pm on Apr 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To display the names while selecting use javascript (There's a javascript forum on webmasterworld) If you want to use php you have to post the form and then
<?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>

I'm not sure what would happen if $_POST["dropdownonsite"] is not an array. However there is a function that checks that. try looking at www.php.net about arrays.
Best regards
Michal Cibor

jusdrum

7:47 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



You can use the onkeyup event parameter in the select tag to run a javascript that will basically submit the form, then the table is built again based on what is selected in the drop-down.

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.