Vì vậy, những gì các dòng trước đó đang làm là tạo ra một mảng mới bên trong phần tử có chỉ số 0 của mảng nhân viên của chúng tôi. Trong ba dòng tiếp theo, bạn đặt giá trị vào các nhân viên mới được tạo ra [0] array. JavaScript làm cho nó dễ dàng để làm điều này: Bạn chỉ cần nhà nước tên của mảng, các nhân viên [0], theo sau bởi một chỉ số trong dấu ngoặc vuông. Chỉ số đầu tiên (0) thuộc. | Chapter 6 HTML Forms Interacting with the User An alternative way of finding out which radio button was clicked would be to loop through the radio button group s array and test each radio button in turn to see if it was checked. The code would look something like this var radindex for radindex 0 radindex radindex if radindex .checked true radCpuSpeedindex radindex break But to get back to the actual code you ll notice a few new-line n characters thrown into the message string for formatting reasons. Next you have your big for statement. for controlindex 0 controlindex numberOfControls controlindex element controlindex if checkbox if true compSpec compSpec n alert compSpec It s here that you loop through each element on the form using controlindex which returns a reference to the element object stored at the controlindex index position. You ll see that in this example the element variable is set to reference the object stored in the form1 array at the index position stored in variable controlindex. Again this is for convenient shorthand purposes now to use that particular object s properties or methods you just type element a period and then the method or property name making your code easier to read and debug which also saves on typing. You only want to see which check boxes have been checked so you use the type property which every HTML element object has to see what element type you are dealing with. If the type is checkbox you go ahead and see if it s a checked check box. If so you append its value to the message string in compSpec. If it is not a check box it can be safely ignored. Finally you use the alert method to display the contents of your message string. 214 Chapter 6 HTML Forms Interacting with the User The select Elements Although they look quite different the drop-down list and the list boxes are actually both elements