P
philip.morgan
I am trying to set a listbox selectedIndex value when writing back to
the client from the server side.
On the client-side form, an onChange event grabs a listbox's value,
length and selectedIndex and then populates individual hidden form
fields in my .asp file (works great). As well, I loop through the
select options and build an html string that is also passed to a
hidden field (also working fine).
=== end code ===
//--- length ---
var str_ReportType_length =
document.getElementById("lbx_ReportType").length
document.getElementById("fld_ReportType_length").value =
str_ReportType_length
//--- selectedIndex ---
var str_ReportType_selectedIndex =
document.getElementById("lbx_ReportType").selectedIndex
document.getElementById("fld_ReportType_selectedIndex").value =
str_ReportType_selectedIndex
//--- value selected ---
var str_ReportType_selected =
document.getElementById("lbx_ReportType").value;
document.getElementById("fld_ReportType_selected").value =
str_ReportType_selected
//--- retrieve the options and build an HTML string ----
var str_ReportType_options = "";
var obj_ReportType = document.getElementById("lbx_ReportType");
for (i=0;i<obj_ReportType.options.length;i++) {
var arr_ReportType = obj_ReportType.options;
str_ReportType_options = str_ReportType_options + "<option value = " +
'"' + arr_ReportType.value + '"' + ">" + arr_ReportType.innerHTML; }
str_startselectHTML ="<select name=" + strQuote + "lbx_ReportType" +
strQuote + " onChange=" + strQuote + "lbx_ReportTypeSelect()" +
strQuote + ">";
var blt_ReportType_options = str_startselectHTML +
str_ReportType_options + str_endselectHTML
document.getElementById("fld_ReportType_options").value =
blt_ReportType_options;
=== end code ===
A response.write demonstrates all the values were captured, moved up
from the client to the server, and then back to rebuild the client
page (e.g. submit). No problem there.
*** Question *** ??
If the user has selected number 3 out of 5 items of the .asp form, how
do rebuild the listbox with the user's selection displayed? I've tried
a number of ways... unsuccessfully.
*** Attempted Solutions ****
For example, I tried setting it on the server side. I obtained the
value from the hidden field transferring the selectedIndex from the
client side (strSelectedIndex):
<% Dim obj_lbx_ReportType
obj_lbx_ReportType = document.GetElementById("lbx_ReportType")
lbx_ReportType.selectedIndex = strSelectedIndex.
%>
Of course, I couldn't set a client side object value on the server
side.......
I've also tried to set a <option = "some value" SELECTED>something</
option> when writing it to/from the client/server. However, this
causes problems when the user repeats the selection... the onChange
fires again and..... you get the picture.
Similarly, setting a flag in a JavaScript function to change the
listbox when writing back causes problems with repeat selection/
submits.
Perhaps a permanent function at the client side that triggers somehow.
I'm out of ideas here.
If you've done this before, please let me know how!
Many thanks.
Phil "My brain is full" Morgan
the client from the server side.
On the client-side form, an onChange event grabs a listbox's value,
length and selectedIndex and then populates individual hidden form
fields in my .asp file (works great). As well, I loop through the
select options and build an html string that is also passed to a
hidden field (also working fine).
=== end code ===
//--- length ---
var str_ReportType_length =
document.getElementById("lbx_ReportType").length
document.getElementById("fld_ReportType_length").value =
str_ReportType_length
//--- selectedIndex ---
var str_ReportType_selectedIndex =
document.getElementById("lbx_ReportType").selectedIndex
document.getElementById("fld_ReportType_selectedIndex").value =
str_ReportType_selectedIndex
//--- value selected ---
var str_ReportType_selected =
document.getElementById("lbx_ReportType").value;
document.getElementById("fld_ReportType_selected").value =
str_ReportType_selected
//--- retrieve the options and build an HTML string ----
var str_ReportType_options = "";
var obj_ReportType = document.getElementById("lbx_ReportType");
for (i=0;i<obj_ReportType.options.length;i++) {
var arr_ReportType = obj_ReportType.options;
str_ReportType_options = str_ReportType_options + "<option value = " +
'"' + arr_ReportType.value + '"' + ">" + arr_ReportType.innerHTML; }
str_startselectHTML ="<select name=" + strQuote + "lbx_ReportType" +
strQuote + " onChange=" + strQuote + "lbx_ReportTypeSelect()" +
strQuote + ">";
var blt_ReportType_options = str_startselectHTML +
str_ReportType_options + str_endselectHTML
document.getElementById("fld_ReportType_options").value =
blt_ReportType_options;
=== end code ===
A response.write demonstrates all the values were captured, moved up
from the client to the server, and then back to rebuild the client
page (e.g. submit). No problem there.
*** Question *** ??
If the user has selected number 3 out of 5 items of the .asp form, how
do rebuild the listbox with the user's selection displayed? I've tried
a number of ways... unsuccessfully.
*** Attempted Solutions ****
For example, I tried setting it on the server side. I obtained the
value from the hidden field transferring the selectedIndex from the
client side (strSelectedIndex):
<% Dim obj_lbx_ReportType
obj_lbx_ReportType = document.GetElementById("lbx_ReportType")
lbx_ReportType.selectedIndex = strSelectedIndex.
%>
Of course, I couldn't set a client side object value on the server
side.......
I've also tried to set a <option = "some value" SELECTED>something</
option> when writing it to/from the client/server. However, this
causes problems when the user repeats the selection... the onChange
fires again and..... you get the picture.
Similarly, setting a flag in a JavaScript function to change the
listbox when writing back causes problems with repeat selection/
submits.
Perhaps a permanent function at the client side that triggers somehow.
I'm out of ideas here.
If you've done this before, please let me know how!
Many thanks.
Phil "My brain is full" Morgan