Project

General

Profile

Feature #2859 » linked_lists.js

Vasia Pupkin, 2009-03-07 09:53

 
1
function number(str, n){
2
  if (n <= 0) return ""; 
3
  else if (n > String(str).length) return str;
4
  else return String(str).substring(0,n);
5
}
6

    
7
function parse(object){
8
  var NodeList = object.getElementsByTagName('option');
9
  var nodes = $A(NodeList); var array = new Array();
10
  for (i=0; i<$(nodes).length; i++){
11
    array[i] = $(nodes)[i].innerHTML;
12
  }
13
  return array;
14
}
15

    
16
function del(object){
17
  var NodeList = object.getElementsByTagName('option'); 
18
  var nodes = $A(NodeList); 
19
  nodes.each(function(node){
20
    if($(node).innerHTML != '--- Выберите ---'){
21
      $(node).remove();
22
    };
23
  });
24
}
25

    
26
function add(object, name) {
27
  object.options.add(new Option(name,name,false,false));
28
}
29

    
30
Event.observe(window, 'load', function() {
31
  var select = $('issue_custom_field_values_13');
32
  var array = parse(select);
33
  del(select);
34
  Event.observe($('issue_custom_field_values_12'), 'change', function() {
35
    del(select);
36
    var block_selected = $F('issue_custom_field_values_12'); 
37
    for(i=0; i<array.length; i++) {
38
      if(number(array[i],1) == number(block_selected,1)) {
39
        add(select,array[i]);
40
      };
41
    };
42
  });
43
});
(1-1/2)