...

View Full Version : Multiple Pop-Up Windows



monique
03-17-2004, 10:39 AM
I used the JavaScript code generated by javascriptkit.com to create a pop-up window. This was successful, but when I tried to create another pop-up window that linked from the same page, the first pop-up window keeps appearing. My links are accurate, so I can't understand why the correct pop-up doesn't appear.

glenngv
03-17-2004, 10:48 AM
Can we see the code?

monique
03-17-2004, 05:25 PM
Of course... here's the snippet.

I'm trying to have the page called civicaddress.htm pop up (I added this one last) but instead the pop-up called pid.htm pops up when I click on the Civic Address text link.


----------------------------------------------------------------------------
<script language="JavaScript">

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
//JavaScript tutorials and over 400+ free scripts

function openpopup(){
var popurl="civicaddress.htm"
winpops=window.open(popurl,"","width=370,height=250")
}
</script>
<a href="javascript:openpopup()">* Civic Address:</a></div></td>
<td class="normaltext" width="153"> <textarea name="Civic_Address" cols="16" rows="3"></textarea>
</td>
<td class="normaltext" width="121"><div align="left">
<script language="JavaScript">

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
//JavaScript tutorials and over 400+ free scripts

function openpopup(){
var popurl="pid.htm"
winpops=window.open(popurl,"","width=370,height=250")
}
</script>
<a href="javascript:openpopup()">* Parcel Identifier &nbsp;&nbsp;(PID):</a>

sad69
03-17-2004, 06:51 PM
Your problem is that you're re-declaring openpopup(), so it's always going to use the last declaration. You just need one function to do the task:


function openpopup(popupurl){
winpops=window.open(popurl,"","width=370,height=250")
}
</script>
<a href="javascript::openpopup('civicaddress.htm'
)">* Civic Address:</a></div></td>
...
<a href="javascript::openpopup('pid.htm')">* Parcel Identifier (PID):</a>
...


You follow? Hope that helps,
Sadiq.

glenngv
03-18-2004, 03:51 AM
Might be off-topic, but...

Why do javascriptkit make that kind of script? It's even featured as one of the most popular scripts there. :rolleyes: I usually see that popup window script being used by newbies who asked for help here. The common mistake is just what the original poster committed. If the function is properly coded (using a parameter), there would be less mistakes for the js newbies.

Just a thought.

sad69
03-18-2004, 07:30 AM
I agree with you glenngv.

I haven't visited javascriptkit's website, but maybe they're just not a bunch of bright people. Some pretty successful people are not all that bright...

I was thinking maybe they're assuming some level of common sense (or programming sense..), but then again it doesn't make sense to hard-code a function. It makes more sense to provide a parameter. Bizarre...

Cheers,
Sadiq.

monique
03-18-2004, 07:04 PM
Hello again,

Thanks for sending me the script Sadiq. I was going to tell you that I followed what you had written, but I didn't want to speak to soon, and alas...

The pop-ups (neither) are not working and when I click on the 'error on page' text in the bottom left of my browser, I get a note saying that the 'popup URL is undefined'.

Both the PID.htm and civicaddress.htm pages are located in the same directory as the page with the pop-up code.

Can you enlighten me? I have only a few strands of hair left on my head.

Thanks,
Monique

---------------------------------------------------------------------------------

<script language="JavaScript">
function openpopup(popupurl){
winpops=window.open(popurl,"","width=370,height=250")
}
</script>

<a href="javascript:openpopup('civicaddress.htm')">* Civic Address:</a></div></td>
<td class="normaltext" width="153"> <textarea name="Civic_Address" cols="16" rows="3"></textarea>
</td>
<td class="normaltext" width="121"><div align="left">
<a href="javascript:openpopup('PID.htm')">* Parcel Identifier (PID):</a></div></td>
<td class="normaltext"> <input name="PID" type="text" id="PID"></td>

Willy Duitt
03-18-2004, 07:25 PM
The script is throwing errors because:
You have popupurl as the parameter
But popurl in the window.open(popurl....
Fix that and it will work.

However, I believe there is still a better way to do this and that is
using the href as intended and passing that value to the function.
This way, if javascript is disabled. the user can still follow the link,
albiet, not in a window.

eg:


<script type="text/javascript">
function openpopup(popurl){
winpops=window.open(popurl,"","width=370,height=250")
}
</script>

<a href="civicaddress.htm" onclick="openpopup(this.href);return false">* Civic Address:</a></div></td>
<td class="normaltext" width="153"> <textarea name="Civic_Address" cols="16" rows="3"></textarea>
</td>
<td class="normaltext" width="121"><div align="left">
<a href="PID.htm" onclick="openpopup(this.href);return false">* Parcel Identifier (PID):</a></div></td>
<td class="normaltext"> <input name="PID" type="text" id="PID"></td>

.....Willy

monique
03-18-2004, 07:49 PM
Thanks Willy.

Is there a way to specify the height and width of each and every pop-up window using the code you posted?

Monique

Willy Duitt
03-18-2004, 08:32 PM
Yes;

Just pass more arguements in the function call.

eg:

<script type="text/javascript">
function openpopup(url,width,height){
winpops=window.open(url,'','top=100,left=275,width='+width+',height='+height);
}
</script>

<a href="civicaddress.htm" onclick="openpopup(href,300,200);return false">* Civic Address:</a></div></td>
<td class="normaltext" width="153">
<textarea name="Civic_Address" cols="16" rows="3"></textarea>
</td>
<td class="normaltext" width="121"><div align="left">
<a href="PID.htm" onclick="openpopup(href,200,400);return false">* Parcel Identifier (PID):</a></div></td>
<td class="normaltext"><input name="PID" type="text" id="PID"></td>

.....Willy

monique
03-18-2004, 09:31 PM
Fantastic. (It works!) Thanks a bunch.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum