Applying users listbox selection when writing back to client
Applying users listbox selection when writing back to client
am 18.01.2008 22:07:32 von 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").valu e =
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
var arr_ReportType = obj_ReportType.options[i];
str_ReportType_options = str_ReportType_options + "
Re: Applying users listbox selection when writing back to client
am 18.01.2008 22:19:26 von reb01501
philip.morgan@cogeco.ca wrote:
> I am trying to set a listbox selectedIndex value when writing back to
> the client from the server side.
ASP generates HTML. When you write the OPTION tags, you have to set the
SELECTED attributes for the options that need to be selected.
If ASP was not involved, and you were writing the html for a listbox
that had several items pre-selected, how would you write that html? Once
you know what it's supposed to look like, modify your server-side script
to generate similar html.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: Applying users listbox selection when writing back to client
am 18.01.2008 22:19:59 von Jon Paal
here's a sample to follow:
http://www.webconcerns.co.uk/asp/combo/combo.asp
Re: Applying users listbox selection when writing back to client
am 19.01.2008 06:30:48 von philip.morgan
On Jan 18, 4:19=A0pm, "Bob Barrows [MVP]"
wrote:
> philip.mor...@cogeco.ca wrote:
> > I am trying to set a listbox selectedIndex value when writing back to
> > the client from the server side.
>
> ASP generates HTML. When you write the OPTION tags, you have to set the
> SELECTED attributes for the options that need to be selected.
> If ASP was not involved, and you were writing the html for a listbox
> that had several items pre-selected, how would you write that html? Once
> you know what it's supposed to look like, modify your server-side script
> to generate similar html.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
Hi Bob:
Thank you for taking the time to respond to my post. Your reply served
to restate my question - how do I set the SELECTED value when writing
back to the client (or in the alternative set the selectedIndex). You
will note that I discussed this issue in my post.
Do you know HOW to do this? Thanks.
Re: Applying users listbox selection when writing back to client
am 19.01.2008 06:34:32 von philip.morgan
On Jan 18, 4:19=A0pm, "Jon Paal [MSMD]"
dot com> wrote:
> here's a sample to follow:
>
> http://www.webconcerns.co.uk/asp/combo/combo.asp
Hi Jon:
Thanks for the reply. However, my question is how to set the SELECTED
value from the server to the client, or in the alternative, set the
selectedIndex value.
Your link discusses a build from an ADODB build and setting the
SELECTED value. Not really applicable, since my code describes a
submit from client to server. I just want to return the listbox with
the same selection that user made.
Any ideas?
Re: Applying users listbox selection when writing back to client
am 19.01.2008 14:41:13 von reb01501
CodeGrinder wrote:
> On Jan 18, 4:19 pm, "Bob Barrows [MVP]"
> wrote:
>> philip.mor...@cogeco.ca wrote:
>>> I am trying to set a listbox selectedIndex value when writing back
>>> to the client from the server side.
>>
>> ASP generates HTML. When you write the OPTION tags, you have to set
>> the SELECTED attributes for the options that need to be selected.
>> If ASP was not involved, and you were writing the html for a listbox
>> that had several items pre-selected, how would you write that html?
>> Once you know what it's supposed to look like, modify your
>> server-side script to generate similar html.
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.
>
> Hi Bob:
>
> Thank you for taking the time to respond to my post. Your reply served
> to restate my question - how do I set the SELECTED value when writing
> back to the client (or in the alternative set the selectedIndex). You
> will note that I discussed this issue in my post.
>
> Do you know HOW to do this? Thanks.
You write it to Response as you wrie the html that creates the option tags.
Again, ASP has no "contact" with client elements other than writing the html
that creates them, so push all thoughts of "selectedIndex" out of your mind.
It would be something like this (air code for illustration purposes):
Response.Write "
If then
Response.Write " selected"
end if
Response.write ">"
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Re: Applying users listbox selection when writing back to client
am 19.01.2008 17:43:41 von Jon Paal
same concept, as you build your dropdown list look for values matching those retrieved from user choices .
When found, mark as SELECTED. if not found, don't mark
Re: Applying users listbox selection when writing back to client
am 19.01.2008 19:03:04 von VK
On Jan 19, 12:07 am, philip.mor...@cogeco.ca wrote:
> I've also tried to set a
Re: Applying users listbox selection when writing back to client
am 19.01.2008 19:05:49 von philip.morgan
On Jan 19, 8:41=A0am, "Bob Barrows [MVP]"
wrote:
> CodeGrinder wrote:
> > On Jan 18, 4:19 pm, "Bob Barrows [MVP]"
> > wrote:
> >> philip.mor...@cogeco.ca wrote:
> >>> I am trying to set a listbox selectedIndex value when writing back
> >>> to the client from the server side.
>
> >> ASP generates HTML. When you write the OPTION tags, you have to set
> >> the SELECTED attributes for the options that need to be selected.
> >> If ASP was not involved, and you were writing the html for a listbox
> >> that had several items pre-selected, how would you write that html?
> >> Once you know what it's supposed to look like, modify your
> >> server-side script to generate similar html.
>
> >> --
> >> Microsoft MVP -- ASP/ASP.NET
> >> Please reply to the newsgroup. The email account listed in my From
> >> header is my spam trap, so I don't check it very often. You will get
> >> a quicker response by posting to the newsgroup.
>
> > Hi Bob:
>
> > Thank you for taking the time to respond to my post. Your reply served
> > to restate my question - how do I set the SELECTED value when writing
> > back to the client (or in the alternative set the selectedIndex). You
> > will note that I discussed this issue in my post.
>
> > Do you know HOW to do this? Thanks.
>
> You write it to Response as you wrie the html that creates the option tags=
..
>
> Again, ASP has no "contact" with client elements other than writing the ht=
ml
> that creates them, so push all thoughts of "selectedIndex" out of your min=
d.
> It would be something like this (air code for illustration purposes):
>
> Response.Write "
>
> If then
> =A0 =A0 Response.Write " selected"
> end if
> Response.write ">"
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"- Hide quoted text -
>
> - Show quoted text -
Aha! I understand what you mean. Like this....
var obj_ReportType =3D document.getElementById("lbx_ReportType");
for (i=3D0;i
{
var arr_ReportType =3D obj_ReportType.options[i];
if(arr_ReportType.value ==
document.getElementById("fld_ReportType_selected").value)
{
//alert('got a match between the array element and the option
selected');
str_ReportType_options =3D str_ReportType_options + "
Re: Applying users listbox selection when writing back to client
am 19.01.2008 19:06:51 von philip.morgan
On Jan 19, 11:43=A0am, "Jon Paal [MSMD]"
dot com> wrote:
> same concept, as you build your dropdown list look for values =A0matching =
those retrieved from user choices .
> When found, mark as SELECTED. =A0if not found, don't mark
Thanks Jon. I found this works....
var obj_ReportType =3D document.getElementById("lbx_ReportType");
for (i=3D0;i
{
var arr_ReportType =3D obj_ReportType.options[i];
if(arr_ReportType.value ==
document.getElementById("fld_ReportType_selected").value)
{
//alert('got a match between the array element and the option
selected');
str_ReportType_options =3D str_ReportType_options + "
Often the concepts get blurred in details. Your help is appreciated.
Re: Applying users listbox selection when writing back to client
am 19.01.2008 19:20:55 von reb01501
CodeGrinder wrote:
> Aha! I understand what you mean. Like this....
>
> var obj_ReportType = document.getElementById("lbx_ReportType");
> for (i=0;i
Actually no, I didn't mean anything of the sort. I posted some server-side
code to generate the html. You've used client-side code. Glad you got it
working the way you want it.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"