Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hope to help me find bugs

Status
Not open for further replies.

zhuzhengyu

Technical User
Jul 21, 2000
19
CN
I write two html files to realize the target:<br>1.function:<br>when I select the ADD_NEW item in the &lt;select&gt; ,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 &lt;select--ADD_NEW&gt;<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>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Untitled Document&lt;/title&gt;<br>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;<br>&lt;script language=&quot;JavaScript&quot;&gt;<br>var myWind=new Array(100); //handle of every modify-window<br>var my=new Array(100); //handle of every &lt;select&gt;<br><br>var idTime;<br>function doLoad(){<br> idTime=setInterval(&quot;poll()&quot;,100);<br><br> for(var i=0;i&lt;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&lt;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&lt;100;i++){<br> if((myWind<i>==0)¦¦((myWind<i>!=0)&&(myWind<i>.closed))){<br> my<i>=it;<br> myWind<i>=window.open(&quot;new.htm&quot;,&quot;name&quot;+i);<br> break;<br> }<br> }<br> }<br> }<br>}<br><br>function poll(){<br> //clear debris<br> for(var i=0;i&lt;100;i++){<br> if((myWind<i>.closed)){<br> myWind<i>=0;<br> my<i>=0;<br> }<br> }<br> for(var i=0;i&lt;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&lt;length;i++){<br> selection<i>=select.options<i>.text;<br> }<br><br> select.length=0;<br> for(var i=0;i&lt;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(&quot;ADD_NEW&quot;);<br> <br> myWind[k].close();<br><br> my[k]=0;<br> myWind[k]=0;<br><br> }<br>}<br>function show(){<br> var str=&quot;&quot;;<br> for(var i=0;i&lt;5;i++){<br> str+=&quot;my&quot;+i+&quot;:&quot;+my<i>+&quot;----&quot;+&quot;myWind&quot;+i+&quot;:&quot;+myWind<i>+&quot;----&quot;+(myWind<i>.closed)+&quot;\n&quot;;<br> }<br> window.alert(str);<br>}<br>&lt;/script&gt;<br>&lt;/head&gt;<br><br>&lt;body bgcolor=&quot;#FFFFFF&quot; onLoad=doLoad() onUnload=doUnload()&gt;<br>&lt;form name=&quot;form1&quot;&gt;<br>&nbsp;&nbsp;&lt;input type=button value=test onClick=show() name=&quot;button&quot;&gt;<br>&nbsp;&nbsp;&lt;select name=&quot;menu1&quot; onChange=doNew(this) &gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;a&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;b&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;ADD_NEW&lt;/option&gt;<br>&nbsp;&nbsp;&lt;/select&gt;<br>&nbsp;&nbsp;&lt;select name=&quot;menu2&quot; onChange=doNew(this) &gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;a1&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;b1&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;ADD_NEW&lt;/option&gt;<br>&nbsp;&nbsp;&lt;/select&gt;<br>&nbsp;&nbsp;&lt;select name=&quot;menu3&quot; onChange=doNew(this) &gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;a2&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;b2&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;ADD_NEW&lt;/option&gt;<br>&nbsp;&nbsp;&lt;/select&gt;<br>&nbsp;&nbsp;&lt;select name=&quot;menu4&quot; onChange=doNew(this) &gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;a2&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;b2&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;option&gt;ADD_NEW&lt;/option&gt;<br>&nbsp;&nbsp;&lt;/select&gt;<br>&lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br>and here attached the html file &quot;new.htm&quot; in the popup window:<br><br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Untitled Document&lt;/title&gt;<br>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;<br>&lt;/head&gt;<br>&lt;body bgcolor=&quot;#FFFFFF&quot;&gt;<br>&lt;form name=form1 method=&quot;post&quot; action=&quot;&quot;&gt;<br>&lt;input type=&quot;text&quot; name=&quot;text1&quot; &gt;<br>&nbsp;&nbsp;&lt;input type=button name=submit value=&quot;Submit&quot; onClick=&quot;document.form1.submit.value='ok';&quot;&gt;<br>&lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top