Prototype.Version
=> 1.5.0

If this problem has been resolved in the newly released V1.5.1, please
let me know.

Here is the problem:

When using document.getElementByClassName on a page generated with
Ruby on Rails (however, not with any of the built in functions, pure
javascript loaded through an include tag, (volunteer.js)), I get my
elements in an array along with several (38 to be exact) undefined
elements. I believe that this is a bug/error in the prototype code. I
have not scanned the prototype code, so I cannot give a specific line
number on this. If anyone finds that this is not the case, then I'll
gladly move my then question to the 'users' group.

The code in question is as follows, a syntax highlighted version can
be found at http://pastie.caboo.se/75582.

function custom_report_setup() {
  elements =
document.getElementsByClassName('custom_report_input'); // You must
include the prototype framework for this to work
  elements = elements.slice(0,15)
  prompt_string = elements.length.toString()
  for(element in elements) {
    prompt_string += elements[element].className + '#' +
elements[element].id + "<br/>"
  }
  document.write(prompt_string);
  truncated_elements = [];
  parent_of_truncated = [];
  i = 0
  for(element in elements) {
    document.write("Starting iteration for '" +
elements[element].className + '#' + elements[element].id + "' (" +
i.toString() + ')' + " ...<br/>");
    id = elements[element].id
    if(id.match(/_truncated/) == -1) {
      elements[element].disabled = true;
    } else {
      truncated_elements.push(elements[element]);
 
parent_of_truncated.push(document.getElementById(elements[element].id.replace(/
_truncated/, "")));
    }
    document.write("Exiting iteration for '" +
elements[element].className + '#' + elements[element].id + "' (" +
i.toString() + ')' + " ...<br/>");
    i++
  }
  for(element in parent_of_truncated) {
    if(parent_of_truncated[element].checked == true) {
      truncated_elements[element].disabled = false;
    } else {
      truncated_elements[element].disabled = true;
    }
  }
}

This is called from the page in a simple wrap:

<script type="text/javascript">
  custom_report_setup();
</script>

The output that is written to the page is as follows:

15custom_report_input#view_type
custom_report_input#activity
custom_report_input#activity_truncate
custom_report_input#e_mail
custom_report_input#name
custom_report_input#comments
custom_report_input#comments_truncate
custom_report_input#character_name
custom_report_input#days
custom_report_input#bio
custom_report_input#bio_truncate
custom_report_input#costume
custom_report_input#costume_details
custom_report_input#costume_details_truncate
custom_report_input#present
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
undefined#undefined
Starting iteration for 'custom_report_input#view_type' (0) ...
Exiting iteration for 'custom_report_input#view_type' (0) ...
Starting iteration for 'custom_report_input#activity' (1) ...
Exiting iteration for 'custom_report_input#activity' (1) ...
Starting iteration for 'custom_report_input#activity_truncate' (2) ...
Exiting iteration for 'custom_report_input#activity_truncate' (2) ...
Starting iteration for 'custom_report_input#e_mail' (3) ...
Exiting iteration for 'custom_report_input#e_mail' (3) ...
Starting iteration for 'custom_report_input#name' (4) ...
Exiting iteration for 'custom_report_input#name' (4) ...
Starting iteration for 'custom_report_input#comments' (5) ...
Exiting iteration for 'custom_report_input#comments' (5) ...
Starting iteration for 'custom_report_input#comments_truncate' (6) ...
Exiting iteration for 'custom_report_input#comments_truncate' (6) ...
Starting iteration for 'custom_report_input#character_name' (7) ...
Exiting iteration for 'custom_report_input#character_name' (7) ...
Starting iteration for 'custom_report_input#days' (8) ...
Exiting iteration for 'custom_report_input#days' (8) ...
Starting iteration for 'custom_report_input#bio' (9) ...
Exiting iteration for 'custom_report_input#bio' (9) ...
Starting iteration for 'custom_report_input#bio_truncate' (10) ...
Exiting iteration for 'custom_report_input#bio_truncate' (10) ...
Starting iteration for 'custom_report_input#costume' (11) ...
Exiting iteration for 'custom_report_input#costume' (11) ...
Starting iteration for 'custom_report_input#costume_details' (12) ...
Exiting iteration for 'custom_report_input#costume_details' (12) ...
Starting iteration for
'custom_report_input#costume_details_truncate' (13) ...
Exiting iteration for
'custom_report_input#costume_details_truncate' (13) ...
Starting iteration for 'custom_report_input#present' (14) ...
Exiting iteration for 'custom_report_input#present' (14) ...
Starting iteration for 'undefined#undefined' (15) ...


As you can see, it is not able to progress pass the start of the 16th
(numbered 15) iteration where firebug shows the error:

  elements[element].id has no properties
  with the line:
    if(elements[element].id.match(/_truncated/) == -1) {   (line 14 in
the paste)

This is in direct conflict with the element.length at the start of the
output, which displays the length of the array as 15 (actually longer,
I'm assuming it's not counting the undefined elements). I don't think
this is an error in the javascript as Konqueror also has an error (it
happens to read the array in reverse), showing the same output in
reverse and failing at the first iteration (numbered 0). It's error is
reported as

  TypeError: Undefined value

I could easily work around this, checking if each element existed
before passing it onto my other code in the block, but that defeats
the purpose of having a function to populate the array with valid
elements! :D

If I have not provided enough information, please let me know and I'll
post more.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to