zhuzhengyu
Technical User
I write two html files to realize the target:<br>1.function:<br>when I select the ADD_NEW item in the <select> ,a new window pop up and wait for the info input. then a new item added.<br>2.method:<br>I use two arrays to make relations between every window poped up and <select--ADD_NEW><br>3.defect:<br>when I close the window poped up manually problem may occurs:the global varible and the related window lose the relation<br>I have tried my best to clear garbage varables,But still bugs:<br>eg:in IE4.0,when I use ADD_NEW to open several windows and then close them manually.Error happens when the last window to be closed will .<br><br>here is my code of html:<br><br><html><br><head><br><title>Untitled Document</title><br><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><br><script language="JavaScript"><br>var myWind=new Array(100); //handle of every modify-window<br>var my=new Array(100); //handle of every <select><br><br>var idTime;<br>function doLoad(){<br> idTime=setInterval("poll()",100);<br><br> for(var i=0;i<100;i++){<br> myWind<i>=0;<br> my<i>=0; <br> }<br>}<br><br>function doUnload(){<br> clearInterval(idTime);<br>}<br><br>function doNew(it){<br> if(it.options[it.selectedIndex].text=='ADD_NEW'){<br> var exist=0;<br> for(var i=0;i<100;i++){<br> if((my<i>==it)&&(myWind<i>!=0)&&(!myWind<i>.closed)){<br> myWind<i>.focus();<br> exist=1;<br> break;<br> }<br> }<br> if(exist==0){<br> for(var i=0;i<100;i++){<br> if((myWind<i>==0)¦¦((myWind<i>!=0)&&(myWind<i>.closed))){<br> my<i>=it;<br> myWind<i>=window.open("new.htm","name"+i);<br> break;<br> }<br> }<br> }<br> }<br>}<br><br>function poll(){<br> //clear debris<br> for(var i=0;i<100;i++){<br> if((myWind<i>.closed)){<br> myWind<i>=0;<br> my<i>=0;<br> }<br> }<br> for(var i=0;i<100;i++){<br> if((my<i>!=0)&&(!myWind<i>.closed)){<br> var value=myWind<i>.document.form1.submit.value;<br> if(value=='ok'){<br> doAdd(i);<br> break; <br> }<br> }<br> }<br>}<br><br>function doAdd(k){<br> if(myWind[k]!=0){<br> var select=my[k];<br> var length=select.length;<br> var selection=new Array(length);<br><br> for(var i=0;i<length;i++){<br> selection<i>=select.options<i>.text;<br> }<br><br> select.length=0;<br> for(var i=0;i<length-1;i++){<br> select.options<i>=new Option(selection<i>);<br> } <br> <br> select.options[length-1]=new Option(myWind[k].document.form1.text1.value);<br> select.options[length]=new Option("ADD_NEW"<br> <br> myWind[k].close();<br><br> my[k]=0;<br> myWind[k]=0;<br><br> }<br>}<br>function show(){<br> var str="";<br> for(var i=0;i<5;i++){<br> str+="my"+i+":"+my<i>+"----"+"myWind"+i+":"+myWind<i>+"----"+(myWind<i>.closed)+"\n";<br> }<br> window.alert(str);<br>}<br></script><br></head><br><br><body bgcolor="#FFFFFF" onLoad=doLoad() onUnload=doUnload()><br><form name="form1"><br> <input type=button value=test onClick=show() name="button"><br> <select name="menu1" onChange=doNew(this) ><br> <option>a</option><br> <option>b</option><br> <option>ADD_NEW</option><br> </select><br> <select name="menu2" onChange=doNew(this) ><br> <option>a1</option><br> <option>b1</option><br> <option>ADD_NEW</option><br> </select><br> <select name="menu3" onChange=doNew(this) ><br> <option>a2</option><br> <option>b2</option><br> <option>ADD_NEW</option><br> </select><br> <select name="menu4" onChange=doNew(this) ><br> <option>a2</option><br> <option>b2</option><br> <option>ADD_NEW</option><br> </select><br></form><br></body><br></html><br><br>and here attached the html file "new.htm" in the popup window:<br><br><html><br><head><br><title>Untitled Document</title><br><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><br></head><br><body bgcolor="#FFFFFF"><br><form name=form1 method="post" action=""><br><input type="text" name="text1" ><br> <input type=button name=submit value="Submit" onClick="document.form1.submit.value='ok';"><br></form><br></body><br></html><br><br><br>