selectAdd.js
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:1k
- function addElement(inputname, selectname) {
- // get the field objects
- var input = document.getElementById(eval('inputname'));
- var select = document.getElementById(eval('selectname'));
- // add element
- select.options[select.options.length] = new Option(input.value, input.value);
- input.value = '';
- }
- function removeFrom(inputname, selectname) {
- // get the field objects
- var input = document.getElementById(eval('inputname'));
- var select = document.getElementById(eval('selectname'));
- if (select.selectedIndex == -1) {
- alert("Please select an item to remove");
- return false;
- }
- for (i=select.options.length - 1;i>=0; i--) {
- if (select.options[i].selected) {
- select.options[i] = null;
- }
- }
- }
- function selectSubmit(selectname) {
- // select all the fields
- var select = document.getElementById(eval('selectname'));
- for (i=select.options.length - 1;i>=0; i--) {
- select.options[i].selected = true;
- }
- }