JavaScript & Select

by "Norman Bunn" <norman.bunn(at)craftedsolutions.com>

 Date:  Wed, 13 Sep 2000 13:10:05 -0400
 To:  <hwg-languages(at)hwg.org>
  todo: View Thread, Original
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 ==
lect-one"){ 
            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.