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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open multiple window using "for" loop

Status
Not open for further replies.

bench

Technical User
Jan 5, 2001
17
0
0
US
Hi
can anyone show me how to open multiple popup window
using myWin.open() in both IE5&N4. This is how I want
it to work. I have a select box which will allow my user
to select multiple sites. After the selection,
I want to popup those sites base upon their preference.
However, when i select, let say 2 sites, my program
will popup six sites which is the same amount of sites
in my select box and that's not what i want.

This is the code i been working with:

<html>
<head><title>Assignment#5</title>

<script language=&quot;JavaScript&quot;>
<!--

function go()
{
var myCars=window.document.myForm.mySites

for (var i=0 ; i < myCars.length ; i++)
{

if (myCars.options.selected)
URL= &quot;[j].value;

var myWind=open(URL,'goCars','height=400,width=400,toolbar=no')
myWind.focus()

}
}

//-->
</script>
</head>
<body bgColor=lightblue>
<form name='myForm'>

<select name='mySites' multiple size=5 >
<option value=' BMW </option>
<option value=' Volkswagen </option>
<option value=' Ford </option>
<option value=' Honda </option>
<option value=' Volvo </option>
</select>
<br>
<input type=button value='show selected' onclick='go()'>
</form>
</body>

</html>
 
Maybe:

Code:
 if (myCars.options[i].selected)
 
Thanks for pointing that out. However, it
was my error why posting the code at this site.
I already tried your that but it still couldn't work

function go()
{
var myCars=window.document.myForm.mySites
var URL;
for (var i=0 ; i < myCars.length ; i++)
{

if (myCars.options.selected)
URL= &quot;.value;

var myWind=open(URL,'goCars','height=400,width=400,toolbar=no')
myWind.focus()

}
}
 
Sorry about!!
Here is the correct code that couldn't work.
Thanks in advance.


Code:
function go()
{       
        var myCars=window.document.myForm.mySites
        var URL;
        for (var i=0 ; i < myCars.length ; i++)
        {

            if (myCars.options[i].selected) 
       URL= &quot;[URL unfurl="true"]http://&quot;+myCars.options[/URL][i].value;

var myWind=open(URL,'goCars','height=400,width=400,toolbar=no')
  myWind.focus()
        
  }
}
 
think your open needs to be nested under the if also

Code:
function go()
                         {       
                                 var myCars=window.document.myForm.mySites
                                 var URL;
                                 for (var i=0 ; i < myCars.length ; i++)
                                 {

                                     if (myCars.options[i].selected){ // this is new
                                              URL= &quot;[URL unfurl="true"]http://&quot;+myCars.options[/URL][i].value;

                                               var                                                           myWind=open(URL,'goCars','height=400,width=400,toolbar=no')
                                              myWind.focus()

                                    } // this is new
                           }
                         }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top