I have a select box that gets filled from a DB query and contains a list of email addresses. I allow the user to multi select email addresses and by way of javascript move the selected email addresses over to another select box.
Now once they have their selected group of email addresses in the second box they hit submit and I process these email addresses. This is what I want.
So how do I access these email addresses on the next page? I need all of the addresses from the second box that they moved over. I am using php on the server side and using the post method on the form. I tried accessing the select list via $HTTP_POST_VARS["editbox"] but it only lists one of the items. I thought that the post vars was setup like an array and I tried to access it like $HTTP_POST_VARS["editbox"][0] but this gave me the first letter of the one email address.
I think you need to change the name of the listbox to have square brackets on the end, i.e. "editbox[]". This should indicate to PHP to turn it into an array.
Thank you for the reply. You are the second person to suggest this so I think this is the right path.
My problem is I am not very good with Javascript and when I change my code to have the "[]" after the name I assume I need to do the same where I reference it in my Javascript. Once I do this my what was working JS code to move the items from one list to the other stops working.
Just for the heck of it I will post my code below...if you can (or have time) it would be great if you could point me in a direction as to how this name="editbox[]" effects my Javascript code or additional changes that need to be made so this array will work. The first edit box is populated by a MYSQL query (I spared you the query code, I tried to keep it short) I am excited that I am one step away from this working (it has been a week now). Again thank you for your time.
My code :
<script LANGUAGE=\"JavaScript\">
<!--// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
// This function copies options between select boxes instead of
// moving items. Duplicates in the target list are not allowed.
// ------------------------------------------------------------------->
function copySelectedOptions(from,to)
{
var options = new Object();
for (var i=0; i<to.options.length; i++)
{
options[to.options[i].value] = to.options[i].text;
}
for (var i=0; i<from.options.length; i++)
{
var o = from.options[i];
if (o.selected)
{
if (options[o.value] == null || options[o.value] == \"undefined\" || options[o.value]!=o.text)
{
to.options[to.options.length] = new Option( o.text, o.value, false, false);
}
}
}
if ((arguments.length<3) || (arguments[2]==true))
{
sortSelect(to);
}
from.selectedIndex = -1;
to.selectedIndex = -1;
}
<!--// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
// Remove all selected options from a list
// (Thanks to Gene Ninestein)
// ------------------------------------------------------------------->
function removeSelectedOptions(from)
{
for (var i=(from.options.length-1); i>=0; i--)
{
var o=from.options[i];
if (o.selected)
{
from.options[i] = null;
}
}
from.selectedIndex = -1;
}
<!--this function is supposed to loop through and select all options on submit to post the vars I need.-->
function White()
{
var opt = document.vblocked.towhite.options;
var j, len = opt.length;
for (j = 0; j < len; j++)
{
opt[j].selected = true;
}
return true;
}
</script>
<!--***************************************END OF JS Functions****************************-->
<!--******irrelevant body info************-->
<table cellpadding=3 cellspacing=5 border=0>
<tr>
<td>
All of the email addresses below have been sent an email
of rejection that they must reply to for proof of legitimacy.
Once they reply they will be added to SpamnIt's Database and
be able to send you email. If you know someone in the list is
legitimate or see a newsgroup/forum address,
<b><a href=../admin/adminwhite.php>Click here</a></b> to add them to your
Whitelist so you can immediately receive email from them.
</td>
</tr>
<tr>
<td>
SpamnIt periodically cleans out these declined emails. If you would like
to clear them sooner, check the <b>delete</b> box and click <b>Submit</b>
to clear all declined email addresses from your list.<p>
</td>
</tr>
</table>
<!--******end of irrelevant body info************-->
<tr>
<td width=20>
<select multiple name=blocked size=15 style=\"width:250;\">";
//here we loop through our query results and build the list of
//blocked email addresses and dates they were blocked.
while ($row = @mysql_fetch_array($result))
{
//here we query the declined table inside this loop for each address
//to see if they are still in there meaning they have not
//replied to the email that was sent to them. We do this
//so we can display a different row color to the user to
//show who has replied after being blocked and who has not.
$query = "select UserID from declined where EmailFrom ='".$row[1]."'";
$result2 = @mysql_query($query);
$row1 = @mysql_fetch_array($result2);
if (!empty($row1[0]))
{
$value .='<Option style=color:red value ='.$row[1].'>'.$row[1]." ".$row[2];
}
else
{
$value .='<Option value ='.$row[1].'>'.$row[1]." ".$row[2];
}
}
//here we run a query to count the total of declined emails for a user a display
//them.
$query = "select count(*) from blockedemails where UserID = ".$HTTP_SESSION_VARS["uid"];
Bookmarks