Jump to content

Listbox Problem


Recommended Posts

optionsT Does not show any results.Dont know where is the problem.

<script type="text/javascript" language="javascript">

function AddItemInList(fromLeftToRight, isAll){
	var list1  = document.getElementById('listBoxF');
	var list2  = document.getElementById('listBoxT');
		if(Boolean(fromLeftToRight) == true){
		return false;
function MoveItems(listFrom, listTo, isAll){
	var toBeRemoved = "";
	if(listFrom.options.length > 0){
		for (i=0; i<listFrom.length; i++){
			if (listFrom.options[i].selected || (isAll == true)){
				if(Exist(listTo, listFrom.options[i].value) == 0){
					listTo[listTo.length] = new Option(listFrom.options[i].text, listFrom.options[i].value, true);
					toBeRemoved = toBeRemoved + listFrom.options[i].value + ';';
	RemoveFromList(listFrom, toBeRemoved);
		alert('Unable to Move Items. List is Empty!');
function RemoveFromList(listFrom, items){
	var toBeRemoved = items.split(';');
	for (var i=0; i < toBeRemoved.length; i++){
		for (var j = 0; j < listFrom.length; j++){
			if (listFrom.options[j] != null && listFrom.options[j].value == toBeRemoved[i]){
				listFrom.options[j] = null;
function ClearSelection(list){
	list.selectedIndex = -1;
function Exist(list, value){
	var flag = 0;
	for (var i=0; i < list.length; i++){
		if (list.options[i].value == value){
			flag = 1;
	return flag;


$opt = isset($_POST['optionsT']) ? $_POST['optionsT'] : '';

	print $opt;

<form method=\"POST\">
<table style=\"width:100%\">
  	<tr valign=\"top\">
        	<select multiple size=\"5\" name=\"optionsF\" id=\"listBoxF\" style=\"width:350px\">
        		<option value=\"1\">1</option>
        		<option value=\"2\">2</option>
        		<option value=\"3\">3</option>
        		<option value=\"4\">4</option>
      		<div align=\"center\">
        		<input type=\"button\" onclick=\"return AddItemInList(true,true)\" value=\"+ All\">
       	 		<input type=\"button\" onclick=\"return AddItemInList(true,false)\" value=\"+\">
        		<input type=\"button\" onclick=\"return AddItemInList(false,false)\" value=\"-\">
        		<input type=\"button\" onclick=\"return AddItemInList(false,true)\" value=\"- All\">
      		<select multiple size=\"5\" name=\"optionsT[]\" id=\"listBoxT\" style=\"width:350px\">
    	<td><input type=\"submit\" name=\"submit\" value=\"Submit\"></td>
Link to comment
Share on other sites

You will need to loop through all the items in the second list and apply the selected attribute to true for each option. To do so add the following code before  return false;  in the  AddItemInList  function

    for(i = 0; i < list2.length; i++) {
        list2[i].selected = true;
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.

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.