//------------------------------------------------------------------------------*/ // copyright notice */ // ~~~~~~~~~~~~~~~~ */ // copyright (c) 2003 by yongchuang electronic commerce co.,ltd. */ // */ // all rights reserved. this material is confidential and proprietary to */ // yongchuang electronic commerce co.,ltd. and no part of this material should */ // be reproduced,published in any form by any means,electronic or mechanical */ // including photocopy or any information storage or retrieval system nor */ // should the material be disclosed to third parties without the express */ // written authorization of yongchuang electronic commerce co.,ltd. */ // */ //------------------------------------------------------------------------------*/ //================================================================ // // file name : controls.js // // file type : javascript source file // // author : andy wang // // purpose : common properties and methods about some html controls // // date : 06/16/2003 // // modification: 06/16/2003 // //================================================================ function textisblank(formkey,thetext){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 validate whether the string is blank // parameters : // name mode description // formkey input the name or index of the form // thetext input the name of the text // // return value : true/false // return type : boolean // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- var ele=document.forms[formkey].elements[thetext]; var thevalue=ele.value; var len=thevalue.length; var i; var beblank=true; //- must not be blank for(i=0;i0){ moveup(formkey,listname) } } function moveup(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : move selected item up // parameters : // name mode description // formkey input the name or index of the form // control input the name of the control // // return value : none // return type : none // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- var indexselected,indexswapped; indexselected=getselectedindex(formkey,listname); if (indexselected >= 0){ indexswapped=indexselected-1; swapitem(formkey,listname,indexselected,indexswapped); } } function movedown(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : move selected item down // parameters : // name mode description // formkey input the name or index of the form // control input the name of the control // // return value : none // return type : none // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- var indexselected,indexswapped; indexselected=getselectedindex(formkey,listname); if (indexselected == getlistlength(formkey,listname) -1 ){ //selected item is top item or no selection return; }else{ indexswapped=indexselected+1; swapitem(formkey,listname,indexselected,indexswapped); } } function movebottom(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : move selected item to the bottom // parameters : // name mode description // formkey input the name or index of the form // control input the name of the control // // return value : none // return type : none // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- if (getselectedindex(formkey,listname)<0) return; while(getselectedindex(formkey,listname) <= getlistlength(formkey,listname)-2){ movedown(listname); } } function moveitem(formkey,fromlist,tolist){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : move selected item from a list to another list // parameters : // name mode description // formkey input the name or index of the form // fromlist input the name of source list // tolist input the name of destination list // // return value : none // return type : none // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- var indexselected; indexselected=getselectedindex(formkey,fromlist); if (indexselected==-1) return; additem(formkey,tolist,document.forms[formkey].elements[fromlist].options[indexselected].text,document.forms[formkey].elements[fromlist].options[indexselected].value ); removeitem(formkey,fromlist); } function copyitem(formkey,fromlist,tolist){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : copy selected item from a list to another list // parameters : // name mode description // formkey input the name or index of the form // fromlist input the name of source list // tolist input the name of destination list // // return value : none // return type : none // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- var i,len; len=document.forms[formkey].elements[fromlist].options.length; for(i=0;i=0;i--){ if(document.forms[formkey].elements[listname].options[i].selected==true){ document.forms[formkey].elements[listname].remove(i); } } len=document.forms[formkey].elements[listname].options.length; if(len>0) document.forms[formkey].elements[listname].options[len-1].selected=true; } function getselectedindex(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : get the selected index // parameters : // name mode description // formkey input the name or index of the form // listname input the name of the list // // return value : the selected index of the list // return type : int // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- return document.forms[formkey].elements[listname].selectedindex; } function getselectedlistvalue(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : get the selected list value // parameters : // name mode description // formkey input the name or index of the form // listname input the name of the list // // return value : the selected value of the list // return type : string // // functions called : none // //-------------------------------------------------------------------------------- var i,len; var result; len=document.forms[formkey].elements[listname].options.length; result=""; for(i=0;i") != -1) return false; else return true; } function clearlist(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : clear select list // parameters : // name mode description // formkey input the name or index of the form // listname input the name of the list // // return value : none // return type : none // // functions called : none // //-------------------------------------------------------------------------------- var i,len; len=document.forms[formkey].elements[listname].options.length; for(i=len-1;i>=0;i--){ document.forms[formkey].elements[listname].remove(i); } } function getlistlength(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : get the length of the list // parameters : // name mode description // formkey input the name or index of the form // listname input the name of the list // // return value : the selected index of the list // return type : int // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- return document.forms[formkey].elements[listname].options.length; } function getlistvaluestring(formkey,listname){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 06/16/2003 select | list : get the string of the list,separated by "," // parameters : // name mode description // formkey input the name or index of the form // listname input the name of the list // // return value : the list string // return type : string // // functions called : 调用的函数 // //-------------------------------------------------------------------------------- var len; var i; var result; result=""; sep=","; len=document.forms[formkey].elements[listname].length; for(i=0;i=0) && (indexswapped>=0) && (indexselected != indexswapped) ){ var thetext,thevalue; thetext=document.forms[formkey].elements[listname].options[indexselected].text; thevalue=document.forms[formkey].elements[listname].options[indexselected].value; newoption1=new option(thetext,thevalue); thetext=document.forms[formkey].elements[listname].options[indexswapped].text; thevalue=document.forms[formkey].elements[listname].options[indexswapped].value; newoption2=new option(thetext,thevalue); document.forms[formkey].elements[listname].options[indexselected]=newoption2; document.forms[formkey].elements[listname].options[indexswapped]=newoption1; //set selectedindex document.forms[formkey].elements[listname].options[indexswapped].selected=true; } } function checkfile(formkey,fileelement,filelist,allowordeny){ //-------------------------------------------------------------------------------- // author : andy wang // version date description // 1.0 08/27/2003 check upload file type // parameters : // name mode description // formkey input the name or index of the form // fileelement input file element name // filelist input allowed or denied file type list ,separated by “,” // allowordeny input allowed or denied // // return value : if check successfully return true ,otherwise return false // return type : boolean // // functions called : none // //-------------------------------------------------------------------------------- var arytemp; var filename; var filetype; var fileliststring="," + filelist + ","; var thefile=document.forms[formkey].elements[fileelement]; var thevalue=thefile.value; var result; var promptstring; var len; var chr; if(thevalue*0==0) return true; fileliststring=fileliststring.tolowercase(); //文件名 arytemp=thevalue.split("\\"); if(arytemp.length==1){ //- 不是选择的文件路径,可能是手动胡乱输入字符 alert("请选择上传的文件!"); settextfocus(formkey,fileelement); return false; } filename=arytemp[arytemp.length-1]; /* //englishchar : validate all characters len=filename.length; for(var i=0;i