Closed Bug 285498 Opened 20 years ago Closed 20 years ago

form select elements not added correctly if index is decremented

Categories

(Core :: DOM: Core & HTML, defect, P2)

x86
Linux
defect

Tracking

()

RESOLVED FIXED
mozilla1.8beta2

People

(Reporter: andrew, Assigned: bzbarsky)

References

()

Details

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a6) Gecko/20041126
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a6) Gecko/20041126

In a JavaScript application from shaw.ca, a form to enter start and end dates
is updated dynamically to reflect the previous 3 years and the number of
days in the selected month. Initially the options array is filled from
HTML. The options length is then zeroed, and new elements are added - 
1 through (28-31) for days and (2005-2003) for years. The days options are
presented correctly, but the years options show only one entry instead of three.
If the years are built by incrementing the index, the options show all
three years.

This page works OK in IE

Bad page: http://andrew.triumf.ca/form_customer_statement.moz2.html
Good page: http://andrew.triumf.ca/form_customer_statement.moz3.html

Reproducible: Always

Steps to Reproduce:
1. Enable scripting
2. Visit page
3. try to select previous year

Actual Results:  
only current year is shown

Expected Results:  
last 3 years should be shown
Andrew, the Core/JavaScript Engine is for JavaScript language issues only. Your
issue is related to the Core/DOM 0.

the issues is the code

for (var threeYears = 2; threeYears >= 0; threeYears--){ 
  tYear = "" + (thisyear - threeYears);
  temp = new Option(tYear,tYear);
  tempYear.options[threeYears]=temp;
}

which fills the options nodelist in from [2],[1],[0] and results in only [0]
remaining.
Assignee: general → general
Component: JavaScript Engine → DOM: Level 0
QA Contact: general → ian
Confirming, I couldn't find a duplicate. Other browsers simply create empty
options (option.text == option.value == "") to fill the elisions, just like
Mozilla does if you set opts.length=4 before setting opts[3].
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached patch Proposed patchSplinter Review
Add the missing options if someone tries to set options[n] for a too-large n.
Attachment #178401 - Flags: superreview?(jst)
Attachment #178401 - Flags: review?(jst)
Comment on attachment 178401 [details] [diff] [review]
Proposed patch

r+sr=jst
Attachment #178401 - Flags: superreview?(jst)
Attachment #178401 - Flags: superreview+
Attachment #178401 - Flags: review?(jst)
Attachment #178401 - Flags: review+
Assignee: general → bzbarsky
Priority: -- → P2
Target Milestone: --- → mozilla1.8beta2
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: