|
 |
asp_web_howto thread: Dynamically Add New Options To SELECT List
Message #1 by "Rita Greenberg" <rg1@h...> on Mon, 26 Mar 2001 19:48:30
|
|
Hi.
I want to dynamically add new options to a SELECT list. I have 2 list
boxes. The user can multiselect from list box1 (oGroups) and I want to add
their selection(s) to list box2 (oSelected).
My problem is I don't know how to set the "Value" attribute for list box2.
The "Value" in list box1 could be e.g. 6 but it could be 1 in list box2. I
thought about converting string to numeric, adding 1 to it, converting
back to string but had problems with that.
I have the following code:
<script language="JavaScript">
<!--
function addtolist()
{
/* Find selected items in list box1 */
var cSelect = document.all.item("oGroups")
for (var i=0;
i<cSelect.options.length; i++) {
/* Check to see if a particular option is selected */
if(cSelect.options(i).selected) {
/* Add new option to list box2 */
var oOption = document.createElement("option");
oOption.text=cSelect.options(i).text;
oOption.value=WHAT GOES HERE??
oSelected.add(oOption)
}
}
}
-->
</script>
TIA
Rita
Message #2 by Rita Greenberg <rg1@h...> on Mon, 26 Mar 2001 13:52:42 -0800
|
|
Please cancel. I was able to find some sample code!
-----Original Message-----
From: Rita Greenberg [mailto:rg1@h...]
Sent: Monday, March 26, 2001 11:49 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Dynamically Add New Options To SELECT List
Hi.
I want to dynamically add new options to a SELECT list. I have 2 list
boxes. The user can multiselect from list box1 (oGroups) and I want to add
their selection(s) to list box2 (oSelected).
My problem is I don't know how to set the "Value" attribute for list box2.
The "Value" in list box1 could be e.g. 6 but it could be 1 in list box2. I
thought about converting string to numeric, adding 1 to it, converting
back to string but had problems with that.
I have the following code:
<script language="JavaScript">
<!--
function addtolist()
{
/* Find selected items in list box1 */
var cSelect = document.all.item("oGroups")
for (var i=0;
i<cSelect.options.length; i++) {
/* Check to see if a particular option is selected */
if(cSelect.options(i).selected) {
/* Add new option to list box2 */
var oOption = document.createElement("option");
oOption.text=cSelect.options(i).text;
oOption.value=WHAT GOES HERE??
oSelected.add(oOption)
}
}
}
-->
</script>
TIA
Rita
|
|
 |