Thanks Russ,

I finally manage to piece together something similar:

<script language="JavaScript" type="text/javascript">
function addemail(journoid, jemail) {
oNewOption = new Option();
oNewOption.text = jemail;
oNewOption.value = journoid;
document.release2.distselect.add(oNewOption, 1);
}
function addcat(catid, cat) {
oNewOption = new Option();
oNewOption.text = cat;
oNewOption.value = catid;
document.release2.distselect.add(oNewOption, 1);
}
function removeitem() {
if(document.release2.distselect.selectedIndex != -1){
var selected = document.release2.distselect.selectedIndex;
document.release2.distselect.options[selected] = null;
}
}


        function showMenu(foo) {
                temp='';
                menuLen=foo.length;
                comma=''
                for (i=0;i<menuLen;i++) {
                j=i+1;
                temp += comma + foo.options[i].value;
                comma=','
                }
                document.release2.distids.value=temp
        }
                </script>

This works a treat. The showMenu function is called onSubmit an builds the hidden list.

Cheers

Dave

At 10/27/2003 10:47, you wrote:
OK here is what I would do.

Don't have the ID  list in the hidden form field, put it in an array.
When the same ID is removed from the select list, remove it from the
array (null it). Then add the list of ID's to the hidden field at the
end when the form is submitted.

//create array
<script language="javascript">
Var IDLIST = new Array();
<cfoutput query="IDLIST">
IDLIST[#currentrow] = #ID#;
</cfoutput>

//function to remove entries

Function removeID()
{
Removeval =
document.formname.selectlist.options[document.formname.selectlist.select
edIndex].value;
document.formname.selectlist.options[document.formname.selectlist.select
edIndex].name = '';
document.formname.selectlist.options[document.formname.selectlist.select
edIndex].value = '';
For(x=0;x<IDLIST.length;x++)
        {
        if(IDLIST[x] == Removeval)
                IDLIST[x] = ''
        }

Function makelist()
{
Obj = document.formname.hiddenfield;
For(x=0;x<IDLIST.length;x++)
        {
        if IDLIST[x] != ''
                obj.value = obj.value + IDLIST[x] + ' ';
        }

And call this function from your delete button with
<input name="delete" onclick="removeID()">

And when you submit form, just add the array values to your hidden form
field.

<form onsubmit="makelist()">

I haven't tested the code, so watch out for my typos :-)


HTH



Russ Michaels Macromedia/Allaire Certified ColdFusion Developer

CFDeveloper
The free resource and community for ColdFusion developer.
http://www.cfdeveloper.co.uk

Join the CFDeveloper discussion lists.
To subscribe send an e-mail to [EMAIL PROTECTED]



> -----Original Message-----
> From: Dave Phipps [mailto:[EMAIL PROTECTED]
> Sent: 27 October 2003 08:00
> To: ColdFusion User group
> Subject: [ cf-dev ] Dynamic javascript select box from function call
>
>
> Hi,
>
> I have the following functions which when called via an href
> add the item
> to the list.  The email appears in the text area and the id
> appears in a
> hidden field.  The problem with this is that if the user
> deletes an email
> address from the text area the list of ids in the hidden
> field is incorrect.
>
> What I want to do is convert these functions so that I can
> dynamically
> build a multi-select drop down list as well as a hidden list
> of id's.  Then
> supply a remove button so that when a user removes an email
> address from
> the list the hidden field is also updated with the values in
> the option array.
>
> I would like to end up with code similar to this:
>       <input type="hidden" name="distids" value="">
>       <select name="distselect" size="10" multiple
> style="width:300px;"
> class="form_field">
>       <option value=""></option>
>       </select>
>       <input type="button" name="remove" id="remove"
> value="Remove Selected"
> class="form_submit">
>
> If this makes sense can anyone help?
>
> Code I have below:
>
> <script language="JavaScript" type="text/javascript">
>       function addemail(journoid, jemail) {
>               if (document.release2.distlist.value.length > 0) {
>                       document.release2.distlist.value =
> document.release2.distlist.value +
> "," + "\n" + jemail;
>                       document.release2.distids.value =
> document.release2.distids.value + ","
> + journoid;
>               } else {
>                       document.release2.distlist.value = jemail;
>                       document.release2.distids.value = journoid;
>               }
>       }
>       function addcat(catid, cat) {
>               if (document.release2.distlist.value.length > 0) {
>                       document.release2.distlist.value =
> document.release2.distlist.value +
> "," + "\n" + cat;
>                       document.release2.distids.value =
> document.release2.distids.value + ","
> + catid;
>               } else {
>                       document.release2.distlist.value = cat;
>                       document.release2.distids.value = catid;
>               }
>       }
> </script>
>
> <input type="hidden" name="distids" value="">
>
> <textarea cols="" rows="" name="distlist" id="distlist" wrap="hard"
> class="form_field" style="width:350px;height:300px;"></textarea>
>
>
> Cheers
>
> Dave
>
>
> --
> ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
>
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED] For human help, e-mail:
> [EMAIL PROTECTED]
>


-- ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]


--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]



Reply via email to