Jump to content

Multiple Selection Lists & PHP


ShibSta

Recommended Posts

Ok, I have 2 multiple selection lists. I am using javascript so that users can select items from list 1 and move them to list 2. When the user submits the form I need my php to get the values he has/she has in list 2...

 

I have done printf($_POST['send_to']); and it only shows one value, even when multiple are selected. I read that I need to change it's name to list_2[] but if I add the brackets to the name my javascript quits working...

 

Any suggestions?

 

Here is my JS/HTML, my PHP is simply printf($_POST['send_to']); which prints the data in the array.

 

<script type="text/javascript">
<!--
function compareOptionValues(a, b)
	{
	var sA = parseInt(a.value, 36);
	var sB = parseInt(b.value, 36);
	return sA - sB;
	}
function compareOptionText(a, b)
	{
	var sA = parseInt(a.text, 36);
	var sB = parseInt(b.text, 36);
	return sA - sB;
	}
function moveDualList(srcList, destList, moveAll)
	{
	if ((srcList.selectedIndex == -1) && (moveAll == false))
		{
		return;
		}
	newDestList = new Array(destList.options.length);
	var len = 0;
	for (len = 0; len < destList.options.length; len++)
		{
		if (destList.options[len] != null)
			{
			newDestList[len] = new Option(destList.options[len].text, destList.options[len].value, destList.options[len].defaultSelected, destList.options[len].selected);
			}
		}
	for (var i = 0; i < srcList.options.length; i++)
		{
		if (srcList.options[i] != null && (srcList.options[i].selected == true || moveAll))
			{
			newDestList[len] = new Option(srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected);
			len++;
			}
		}
	newDestList.sort(compareOptionValues);
	for (var j = 0; j < newDestList.length; j++)
		{
		if (newDestList[j] != null)
			{
			destList.options[j] = newDestList[j];
			}
		}
	for (var i = srcList.options.length - 1; i >= 0; i--)
		{
		if (srcList.options[i] != null && (srcList.options[i].selected == true || moveAll))
			{
			srcList.options[i] = null;
			}
		}
	}
	//-->
</script>


			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td width="150" valign="top">
						<select name="list" style="width:150px; height:100px; font-size:10px" multiple="multiple" size="6" ondblclick="moveDualList( this.form.list,  this.form["send_to[]"][0], false )">
							<!-- BEGIN user_list -->
							<option value='{UID}'>{UID} - {USERNAME}</option>
							<!-- END user_list -->
						</select>
										</td>
					<td width="150" align="center" valign="middle">
						<input style="width: 120px; margin: 2px 0 2px 0; font-size: 10px;" type="button" value="Add Selected  »" onclick="moveDualList( this.form.list, this.form["send_to[]"][0], false )"/>
						<input style="width: 120px; margin: 2px 0 2px 0; font-size: 10px;" type="button" value="«  Remove Selected" onClick="moveDualList( this.form["send_to[]"][0], this.form.list, false )"/>
						<input style="width: 120px; margin: 2px 0 2px 0; font-size: 10px;" type="button" value="Add All  »" onClick="moveDualList( this.form.list, this.form["send_to[]"][0], true )"/>
						<input style="width: 120px; margin: 2px 0 2px 0; font-size: 10px;" type="button" value="«  Remove All" onClick="moveDualList( this.form["send_to[]"][0], this.form.list, true )"/>
					</td>
					<td valign="top">
						<select name="send_to[]" style="width:150px; height:100px; font-size:10px" multiple="multiple" size="6" onDblClick="moveDualList( this.form["send_to[]"][0], this.form.list,  false )">
						</select>
					</td>
				</tr>
			</table>

 

I did post this in the PHP section, I wasn't really thinking that it had more to do with JS... (Braindead. Sorry.)

Link to comment
Share on other sites

I have tried several variations of quotes, I cannot get it to work. I am new to javascript and normally stick to PHP. Could you please show me how it needs edited as I tend to be more of a visual learner... It seems like the quotes would be a logical answer to the issue but I cannot get it working properly...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.