Re: JavaScript & Select
by "Norman Bunn" <norman.bunn(at)craftedsolutions.com>
|
| Date: |
Tue, 26 Sep 2000 14:24:24 -0400 |
| To: |
<hwg-languages(at)hwg.org> |
| References: |
FSODOM FSODOM2 |
| |
todo: View
Thread,
Original
|
|
I figured out a solution. May not be elegant, but it works. I create the
selection with 100 options and then use a function called by onLoad to
reduce it back to a single option. The same function called by onChange
updates the option list to max out at the desired quantity. Now when the
form is submitted and the back button is pressed, the options go back to
selected quantity. A few problems, however: 1) a back button with a
quantity of more than 100 doesn't work right, 2) if Javascript is disabled,
the quantity will not update properly and the option list will have 100
entries when it should be one, 3) if something other than the quantity is
chosen, it reverts back to the quantity when the back button is pressed.
I also added a dummy button that says "Update Quantity" to prompt the user
to click it, which removes focus and prompts the onChange method.
So it goes...
Norman
----- Original Message -----
From: Norman Bunn <norman.bunn(at)craftedsolutions.com>
To: <hwg-languages(at)hwg.org>
Sent: Monday, September 18, 2000 3:13 PM
Subject: Re: JavaScript & Select
> The interesting thing is the page maintains the updated information when
> resubmitted, unless it is changed to "1". Apparently, the array for the
> select statement is refreshed to the initial setup on using the BACK
button,
> but the selected option is maintained even if it does not appear on the
> option list.
>
> Any ideas on how to get the page to work properly when the BACK button is
> pressed?
>
> Norman
>
> ----- Original Message -----
> From: Norman Bunn <norman.bunn(at)craftedsolutions.com>
> To: <hwg-languages(at)hwg.org>
> Sent: Wednesday, September 13, 2000 1:10 PM
> Subject: JavaScript & Select
>
>
> > I have a page with the following HTML.
> >
> > <BODY BGCOLOR="#FFFFFF" BODY="onLoad=packageQty()">
> > <input type=text name=Quantity value=1 size=4 maxlength=4
> > onChange="packageQty()">
> > <SELECT NAME=PKG_Qty_02><OPTION VALUE=1 selected>1</OPTION></SELECT>
> >
> > When the value in the quantity field is changed or the page loads, the
> > option list changes based on the JavaScript function below. Everything
> > works as expected, except when the form is submitted and then the BACK
> > button is pressed. Instead of a list matching the quantity value, I get
a
> > blank option displayed with "1" as the only other option. This happens
> only
> > when the quantity is changed before submitting. Ideally what I would
like
> > is for the items to reflect their values immediately prior to
submission.
> > Any ideas on how to make this work correctly?
> >
> > function packageQty()
> >
> > for (var i=0; i<document.submit.elements.length; i++)
> >
> >
> > if (document.submit.elements[i].type ==
> >
>
ne"){
> > var valString = document.submit.elements[i].name;
> > if (valString.match(/(PKG_Qty_)/)){
> > for (var j=1; j<=document.submit.Quantity.value; j++)
> > {
> > document.submit.elements[i].options[j-1] = new Option(j,j,document.submit.Quantity.value,document.submit.Quantity.value);
> > }
> > }
> > }
> > }
> > }
>
> >
> >
> >
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.