Closed Bug 105945 Opened 23 years ago Closed 23 years ago

JavaScript doesn't detect array length of partially generated option lists

Categories

(Core :: Layout: Form Controls, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: P.Edelman, Assigned: rods)

References

Details

Attachments

(1 file)

From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:0.9.5+) Gecko/20011018
BuildID:    2001101822

If an HTML options list is genegrated dynamically by JavaScript, the options
array is not always filled. I tried four different cases:

1. If the entire list including its enclosing tags (<select> and </select>) are
generated by JavaScript, everything is just fine.
2. If normal HTML is used to start the list and only the <option> tags are
generated, the generated options are not recognized, i.e. the options array
length is 0.
3. As in 2, but with a non-generated html <option> is added after the 
JavaScript code, the options array length is 0 too.
4. As in 2, but with a non-generated html <option> is added before the
JavaScript code. This works just fine.

Previous to milestone 0.9.5, this always worked.
I included my test file below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <form name="test_form">
      <select name="test_select1"
onChange="alert(this.options[this.selectedIndex].value);">
        <script language="JavaScript">
          var i = 0;
          document.writeln('<option value='+i+++'>Foo');
          document.writeln('<option value='+i+++'>Bar');
        </script>
      </select>

      <script language="JavaScript">
          var i = 0;
          document.writeln('<select name="test_select2"
onChange="alert(this.options[this.selectedIndex].value);">');
          document.writeln('<option value='+i+++'>Foo');
          document.writeln('<option value='+i+++'>Bar');
          document.writeln('</select>');
      </script>	

      <select name="test_select3"
onChange="alert(this.options[this.selectedIndex].value);">
        <script language="JavaScript">
          var i = 0;
          document.writeln('<option value='+i+++'>Foo');
          document.writeln('<option value='+i+++'>Bar');
        </script>
	<option value=2>Baz
      </select>

      <select name="test_select4"
onChange="alert(this.options[this.selectedIndex].value);">
	<option value=0>Baz
        <script language="JavaScript">
          var i = 1;
          document.writeln('<option value='+i+++'>Foo');
          document.writeln('<option value='+i+++'>Bar');
        </script>
      </select>

    </form>
    <script language="JavaScript">
      alert(document.test_form.test_select1.options.length);
      alert(document.test_form.test_select2.options.length);
      alert(document.test_form.test_select3.options.length);
      alert(document.test_form.test_select4.options.length);
    </script>
  </body>
</html>



Reproducible: Always
Steps to Reproduce:
1. Load the included file
2. It reports the lengths of the options arrays for all three test cases


Actual Results:  In case 1 and 3, the length of the options arrays are 0, and
elements of the list are not recognized.

Expected Results:  As in case 2 and 4, the options array should be filled with
the generated options.
jkeiser, I bet this is fixed by your patch too?  :)
Assignee: rogerl → rods
Component: Javascript Engine → HTML Form Controls
QA Contact: pschwartau → madhur
Wow, a new one :)  Yep, it's fixed.

The reporter's testcase is messed up due to attempting to embed ' inside ', but
the first testcase works.

I am surprised that this ever worked (reliably at least).
Status: UNCONFIRMED → NEW
Depends on: 34297
Ever confirmed: true
Fixed with bug 34297 landing.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
verified fixed on linux 7.1 buildID: 2001-11-20-08trunk
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: