��� ����: ����� ����� / ����� 5 / �� 10
 


������ �� ��� �- JavaScript
 


���� ������ ��:
1: ���� ������ 5
2: ���� ������
3: ���������� �����
4: ����� ���� �����
5: ���� �����
6: ������� ���� �����
7: CheckBoxes
8: ������ ����
9: ������
10: ����� onChange
11: ����� �� ����� 5
|
|
|
|
|
|
|
|
|
|
|
|

����� 5

�� 10: �- onChange ������� ���� ������.

����� �� ������ ���� ��� �� ��� �� ����� ����, ���� ��� ����, ���.

My favorite animal is ...

�����, ��� ��� JavaScript ����� ����, ���� ����� ������� �� �����. ���� �� ��� ����� ����� ����:

<form name="the_form">

<select name="choose_category" onChange="swapOptions(window.document.the_form.choose_category.options[selectedIndex].text);">
  <option selected>Dogs
  <option>Fish
  <option>Birds
</select>

<select name="the_examples" multiple>
  <option>poodle
  <option>puli
  <option>greyhound .
</select>

</form>

����� ��"� �� ��� �������, ����� �- pulldown select ������ �- list select. �-pulldown select �� ����� (handler) �- onChange ����� ��� �������� �- ()swapOptions. ������� �� ������ �- header, ����� ����� ���: ����� ��� ����.

�����, ����� �� �- header. ���� ������ ����� ��� ������ ������ �����:

var dogs = new Array("poodle","puli","greyhound");
var fish = new Array("trout", "mackerel", "bass");
var birds = new Array("robin", "hummingbird", "crow");

��� �� �������� ���� ����� ����� ���� ����� ����� �- pulldown. ����� ���� ����. �����, ����� �������� ������� ���� ����� ����� �-pulldown �����:

function swapOptions(the_array_name)
{
  var numbers_select = window.document.the_form.the_examples;
  var the_array = eval(the_array_name);
  setOptionText(window.document.the_form.the_examples, the_array);
}

������ ��������� ���� ����� ���: the_array_name. �� ����� ���� �� ����� �- pulldown ������ "��", �� the_array ������ �-"��".

����� ������� ���� �������� ����� �� ������ ������ ������ ����� ����, ����� �������.

����� ������ ����� ���� ���: eval(). �������� eaval() ��� ������ ���� ���� ���� �������� �����. ������ ������ �� ����� ������ ��� ������� the_array ������ ������ ������� ����. �� �� �����: the_array_name ���� "��", �� �-the_array ������ ����� �� �"��".

����� ������� �������� ������ ������� ���� ������: setOptionText(). ������� �� ����� �� ������ �� ����� ������� ����� �� the_array. ��� �����:

function setOptionText(the_select, the_array)
{
  for (loop=0; loop < the_select.options.length; loop++)
  {
    the_select.options[loop].text = the_array[loop];
  }
}

�������� ����� ��� �������, �������� ������ ������ ������. ����� ������� �� �������� ����� ������, ������ �� �� ��������� ������� ������. ����, �������� �� ��������� ������� ������ �� ���� �� �� �������� ������. ���, ��� ���� ���� ��� �������� �� ������ �"� ����� ����� �����. �� ������ �����.

���� ������� ���� ���� �� ������, ������ �� ������ ���� �- 0. �� ��� ����� �����:

the_select.options[0].text = the_array[0];

�� ���� �-"��" ������ �- pulldown, the_array[0] ����� ��� "�����", �� ������ ��� ���� �� ������� ������� ������ ������ �"�����". ���� ���� ����� �����, ��� ����� ������ ���� 1, ��� ������� ������ ������ ������ ������ ���� �� "����".

���� ����� ����� ��� ������ ��. ���� ��� ���� �� ���� ���������, ����� �� ������ �� �����. �� ��� ���� ����� �� �������� ����� ����� ��� ����, ��� �������� ����� �����.

��� ��� ����� �� �����, ��� �"� ����� ������ ���� ��� ���� ���� �������. ���, ����, ����� ��:

"<option>greyhound          ."

(������� ������).

��� �� ������ �������� �� ��� ����� �� ���� ������ ���. �� �����, ��� ����. �����, ����� ���� ��� ������ ���� �����, ��� ���� ���� �� JavaScript, �� ���� �� ��� ���� ���� �� ����� ���� ������ ���� ������ ��. ���� ������ ����, ���� ������ ������ �� ����.

���� ������ ���

��� ��� «--

 
       
       
   
 
 

���� ����
����� �����
����� �����
����� ������
����� ���
��� ����