Her's how I did it.  Note that on submit I validate the form.  If all is ok I 
select all items in the second listbox.



<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function AddIt() {

        formObj=document.combo_box;

        if ((formObj.list1.selectedIndex < 0))

        {

                alert("No Item To Add was Selected");

        }

        else

        {

                var SelInd = formObj.list1.selectedIndex;

                var SelText = formObj.list1.options[SelInd].text;

                var SelValue = formObj.list1.options[SelInd].value;

                var newOpt = new Option(SelText, SelValue);

                var selLen = formObj.list2.length;

                formObj.list2.options[selLen] = newOpt;

        }

}

function DropIt() {

        formObjr=document.combo_box;

        if ((formObjr.list2.selectedIndex < 0))

        {

                alert("No Item To Remove was Selected");

        }

        else

        {

                var SelInd = formObjr.list2.selectedIndex;

                formObjr.list2.options[SelInd] = null;

        }

}

function checkall(){

        var blength = document.combo_box.list2.options.length;

        if (document.combo_box.list2.options.length>0){

        var howmany = document.combo_box.list2.options.length;

        for( var count = 0; count < howmany; count++)

        document.combo_box.list2.options[count].selected=true;

        }

        return true;

}

function ValidateForm() {

        formObj=document.combo_box;

        var msg = "";

        // do validation, if errors put text in msg

        if (msg.length > 0) 

        {

                // have errors

                alert (msg);

                return false;

        }

        else

        {

                // no errors on form select all in list2

                checkall();

                return true;

        }

}

//  End -->

</script>

....

<form name="combo_box" action="FormAction.cfm" method="post"  onSubmit="return 
ValidateForm()">

....

<select size="15" name="list1">

        <cfloop query="myquery">

                <option value="#val#">#description#</option>

        </cfloop>

</select>

....

<input type="button" onClick="AddIt()" value=" Add "><br><br>

<input type="button" onClick="DropIt()" value=" Remove ">

....

<select multiple size="15" name="list2">

        

</select>

....

</form>

....







 --- On Tue 05/17, Paul Henderson < [EMAIL PROTECTED] > wrote:

From: Paul Henderson [mailto: [EMAIL PROTECTED]

To: [email protected]

Date: Tue, 17 May 2005 13:49:14 -0400

Subject: RE: Javascript / Listbox Form Problem



Thanks Adam and Rebecca for the response, Adam I do have the listbox set 
up<br>to allow multiple selections:<br><br><select name="lbxSelectedTheme"  
multiple size=5><br><br>But because the user is adding items from one listbox 
into another, at the<br>time the form is submitted the items are not 
selected.<br><br>Apparently this code I'm trying to work with has worked 
properly in the<br>past, it sure won't work for me.<br><br>// Get selected 
themes<br>          for (i=1; i< document.frmImageAdm.lbxSelectedTheme.length; 
i++) {<br>           if (vThemes == "")      {<br>                   vThemes = 
document.frmImageAdm.lbxSelectedTheme.options[i].value<br>            } else 
{<br>                    vThemes = vThemes + "," 
+<br>document.frmImageAdm.lbxSelectedTheme.options[i].value<br>         }<br>   
}<br>   document.frmImageAdm.hdnThemes.value = vThemes<br><br>Despite this 
above code, hdnThemes is always NULL when I try to reference<br>it, but maybe 
because OnSubmit hdnThemes is passed as NULL however, this<br>function SHOULD 
update it's 
value.<br><br>Thanks again for all the help, hopefully you can find your past 
code Adam.<br><br>-Paul<br><br><br><br><br>-----Original Message-----<br>From: 
Adam Haskell [mailto:[EMAIL PROTECTED]<br>Sent: Tuesday, May 17, 2005 1:28 
PM<br>To: CF-Talk<br>Subject: Re: Javascript / Listbox Form 
Problem<br><br><br>I'll search for my page that does that but the gist of it is 
move the<br>items over then select all items onSubmit. The key to getting this 
to<br>work is make sure the second select box has the ability to 
select<br>multiple items.<br><br>Adam H<br><br>On 5/17/05, Rebecca Wells 
<[EMAIL PROTECTED]> wrote:<br>> I don't think that's possible. I have built 
pages that have the multiple<br>select option. What you have to do is submit 
the selected items from the<br>list1 to the action page (using an "Add" or 
"-->" button), which inserts<br>eacho of the selected items to a db table, then 
return to the display page<br>with the selected items added to, or subtracted 
from, 
the list2. The user<br>can use a "Delete" or "<--" button to remove selected 
items from list2, and<br>it works the same way as the add button. They make 
their choices from list2,<br>select the Delete button, which submits to the 
action page, detects that the<br>Delete button was selected and loops over the 
list2 form members, deleting<br>them from the db table, and returns to the 
display page showing those items<br>gone from list2. Yes, that may seem like a 
lot of work, but I haven't<br>figured out any simpler way to do this kind of 
user interface. I hope that<br>makes sense.<br>><br>> >It seems to only output 
the value if an item has been selected, but my<br>goal<br>> >is to on one 
submit get the value of everything that's been added to the<br>> >list 
box?<br>><br>><br><br><br><br>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:207014
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to