Can anyone advise how I can display a list of names in a combo box and add (multiple) selected names to a textbox, delimited by a ';' (semi-colon)? I am trying to build a list of email addresses to pass to a CDONTS mail object.
1. Put the following code in the <HEAD> tags in your page:
<script language="JavaScript">
function append_name(){
var bContinue
var NewName
var SelectedNames
var AlreadySelected
bContinue=true
if (bContinue==true){
if (document.frmTest.cboList.value=="NoSelection"{
bContinue=false
}
}
if (bContinue==true){
NewName=document.frmTest.cboList.value;
SelectedNames=document.frmTest.txtNames.value;
AlreadySelected = SelectedNames.indexOf(NewName);
if (AlreadySelected>-1){
bContinue=false
}
}
if (bContinue==true){
if (document.frmTest.txtNames.value!=""{
document.frmTest.txtNames.value=document.frmTest.txtNames.value+";"+document.frmTest.cboList.value
} else {
document.frmTest.txtNames.value=document.frmTest.cboList.value
}
}
}
</script>
2. put the following code inside the <SELECT> tag:
onchange="append_name(); return true"
so that the <SELECT> tag will look something like this:
3. Make the first entry in the list a dummy entry, which does not have an e mail address, but has the value NoSelection
IE make the first <Option> tag something like this:
NOTE: It is very important that you have the first option in the select list, as then the first e mail address is not selected by default and the change event of the list box will be fired when selecting the first e mail address.
Code within the JavaScript function deals with the user selecting the non-valid e mail address entry
As an example of a complete page, you could have something like this:
<HTML>
<HEAD>
<script language="JavaScript">
function append_name(){
var bContinue
var NewName
var SelectedNames
var AlreadySelected
bContinue=true
if (bContinue==true){
if (document.frmTest.cboList.value=="NoSelection"{
bContinue=false
}
}
if (bContinue==true){
NewName=document.frmTest.cboList.value;
SelectedNames=document.frmTest.txtNames.value;
AlreadySelected = SelectedNames.indexOf(NewName);
if (AlreadySelected>-1){
bContinue=false
}
}
if (bContinue==true){
if (document.frmTest.txtNames.value!=""{
document.frmTest.txtNames.value=document.frmTest.txtNames.value+";"+document.frmTest.cboList.value
} else { document.frmTest.txtNames.value=document.frmTest.cboList.value
}
}
}
</script>
</HEAD>
<BODY>
<form name="frmTest" action="test2.asp" method="POST">
<select name="cboList" onchange="append_name(); return true">
<option value="NoSelection">Select Recipients
<option value="email1">name1
<option value="email2">name2
<option value="email3">name3
<option value="email4">name4
<option value="email5">name5
<option value="email6">name6
<option value="email7">name7
<option value="email8">name8
<option value="email9">name9
</select><BR><BR><BR>
<input type="text" name="txtNames" size="80">
</form>
</BODY>
</HTML>
Just want to say that your help was right on target - exactly what I was trying to achieve. I didn't expect anything half so detailed - thanks very much.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.