Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Pop-Up Windows

    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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Can we see the code?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Pop-up windows

    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="javascriptpenpopup()">* 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="javascriptpenpopup()">* Parcel Identifier &nbsp;&nbsp;(PID):</a>

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    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.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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. 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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Mar 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Pop-up Windows

    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="javascriptpenpopup('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="javascriptpenpopup('PID.htm')">* Parcel Identifier (PID):</a></div></td>
    <td class="normaltext"> <input name="PID" type="text" id="PID"></td>

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <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
    Last edited by Willy Duitt; 03-18-2004 at 06:27 PM.

  • #9
    New Coder
    Join Date
    Mar 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Pop-up Windows

    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

  • #10
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes;

    Just pass more arguements in the function call.

    eg:
    Code:
    <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

  • #11
    New Coder
    Join Date
    Mar 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Fantastic. (It works!) Thanks a bunch.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •