Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → Javascript help
Javascript help
2007-04-28, 7:41 AM #1
I'm trying to do a basic set of functions that will copy values from one multiple select to another multiple select. Here is the Javascript:

Code:
		function addOwners(addSelect, delSelect) {

			var add = document.getElementById(addSelect);
			var del = document.getElementById(delSelect);

			// Get the names in the "users to be added" selection and the current owners select
			var addOwners = add.options;
			var curOwners = del.options;

			// If a user is selected, add that user to the current owners list
			var i = 0;
			for (i = 0; i < addOwners.length; i++) {

				// If the object exists
				if (addOwners) {

					if(addOwners.selected) {

						var index = curOwners.length;
						curOwners[index] = new Option(addOwners.text, addOwners.value, false);

						// Remove the reference to this object
						addOwners = null;

						// We set i to be -1 so that the for loop will increment it to 0 and
						// re-iterate through the list
						i = -1;

					}

				}

			}

		}


And here's some sample HTML:

Code:
			<table style="width: 100%">

				<tr>
					<td style="width: 40%; text-align: right">

						<select name="delOwners[ ]" id="selectNonowners" style="height: 7em;" MULTIPLE>

						<option value="2">afrotiff</option>
						<option value="1">jrh3k5</option>
						<option value="7">mkb</option>

						<option value="6">Omega6744</option>
						<option value="4">tnb324</option>
						<option value="3">TootSweetie85</option>

						</select>

					</td>
					<td style="width: 20%; text-align: center">

						<span class="smalltext">

						<input type="button" onClick="javascript:addOwners('selectNonowners', 'selectOwners')" value="Add >>" />

						<p />

						<input type="button" onClick="javascript:delOwners('selectNonowners', 'selectOwners')" value="<< Remove" />

						</span>

					</td>

					<td style="width: 40%; text-align: left">

						<select name="addOwners[ ]" id="selectOwners" style="height: 7em;" MULTIPLE>


						</select>

					</td>

				</tr>

			</table>


The problem is that, when the PHP file does a count() of $_POST['addOwners'], it returns 0 if I add or remove any users. Any idea why?
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken
2007-04-28, 7:57 AM #2
I'm no js expert but in regards to multiselect boxes, remember, when the form is submitted, none of the values are submitted unless they're SELECTED inside the box. So if you fill the box with all the options, but you don't select them, nothing will get sent. Most people have an onClick handler on the submit button to select all the options when the form is submitted.
2007-04-28, 8:01 AM #3
Oh, right. Duh.
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken

↑ Up to the top!