Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8944331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:59:46+00:00 2026-06-15T11:59:46+00:00

I am looking for a solution that will allow me to combine two scripts

  • 0

I am looking for a solution that will allow me to combine two scripts and have them working together in a cross-browser friendly manner and comply with XHTML 1.0 Transitional standards.

First script is open file/location based on dropdown selection.

Here’s the script:

<script type="text/javascript">
//<![CDATA[
<!--
function go(){ 
if (document.fooform.fooselect.options[document.fooform.fooselect.selectedIndex].value != "none") { 
location = document.fooform.fooselect.options[document.fooform.fooselect.selectedIndex].value 
    } 
} 
//-->
//]]>
</script> 

Here’s the markup:

<form name="fooform">
<select name="fooselect">
   <option selected="selected" value="#">Select a file</option>
   <option value="pdfs/somefile1.pdf">file 1</option>
   <option value="pdfs/somefile2.pdf">file 2</option>
   <option value="pdfs/somefile3.pdf">file 3</option>
   <option value="pdfs/somefile4.pdf">file 4</option>
 </select>
   <input onclick="go()" type="button" value="Get PDF" />
</form>

pretty straight-forward…

The second script is ofcourse, as the title states, one that opens a centered popup.

Here’s the script:

<script type="text/javascript">
//<![CDATA[
<!--
function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 
//-->
//]]>
</script>

Here’s the markup:

<input onclick="PopupCenter('http://www.stackoverflow.com', 'popfoo',400,400);" type="button" value="Open Center Popup" />

So my challenge is to create a script that when the user clicks the “Get PDF” button, a centered popup opens containing the PDF file, and that PDF file will change depending on the option they chose from the dropdown list.

I’m going to have multiple dropdowns on the page, so most likely the scripts will change from document.fooform.fooselect.options to document.form1.select1.options, document.form2.select2.options, etc…and functions will be like go1(), go2(), etc…

Any help/tips/suggestions are greatly appreciated!

UPDATE Thu, November 22nd, 2012

I’ve thought about sacrificing the centered popup feature in lieu of just getting this script to open the PDF in a new window, so far I’ve attempted:

<input type="button" value="Get PDF" onclick="window.open(go().href); return false;" />

as well as

<input type="button" value="Get PDF" onclick="window.open(go(), 'USER GUIDE', 'width=500,height=300');" />

but both of these inputs simply open the PDF in the same window and that’s what I’m trying to avoid.

And if I simply try merging the two above scripts like so:

<script type="text/javascript">
//<![CDATA[
<!--
function PopupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    }

    var go = function go() { 
if (document.fooform.fooselect.options[document.fooform.fooselect.selectedIndex].value != "none") { 
location = document.fooform.fooselect.options[document.fooform.fooselect.selectedIndex].value 
    } 
} 
//-->
//]]>
</script> 

and then use the following input trigger:

<input onclick="PopupCenter('go()', 'popfoo',400,400);" type="button" value="Get PDF" />

or

<input onclick="PopupCenter('go', 'popfoo',400,400);" type="button" value="Get PDF" />

I get error message:

Windows Internet Explorer

Cannot find ‘file:///W:/test/go()’. Make sure the path or Internet address is correct.

[OK]

or

Windows Internet Explorer

Cannot find ‘file:///W:/test/go’. Make sure the path or Internet address is correct.

[OK]

and if I try without the single quotes in the input like so

<input onclick="PopupCenter(go(), 'popfoo',400,400);" type="button" value="Get PDF" />

I get the error message:

Windows Internet Explorer

Cannot find ‘file:///W:/test/undefined’. Make sure the path or Internet address is correct.

[OK]

and then the PDF opens in the same window after I click OK on the error message.

Please help!! Many thanks in advance 🙂

UPDATE 2 Thu, November 22nd, 2012

Got it working in IE (only, unfortunately) in this fiddle

Basically changed then location = document.fooform.fooselect.options[document.fooform.fooselect.selectedIndex].value and declared location as a variable (which I believe is a not a good idea since location is a global variable – if someone could shed some light on that, it would be great) and then added the line window.open(location)

Would like to get it cross browser friendly and hopefully get some help tweeking the new window call (would still like to center it and preferably strip some unneeded things out of the new window like the toolbar, statusbar, etc etc)

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:59:47+00:00Added an answer on June 15, 2026 at 11:59 am

    Doesn’t center the popup, but does what I need (primarily) to do. See jsfiddle http://jsfiddle.net/77buX/

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <title>test</title>
        </head>
        <body>
            <script type="text/javascript">
                var UG1 = function getUG1() {
                    if (document.form1.select1.options[document.form1.select1.selectedIndex].value != "none") {
                        var location = document.form1.select1.options[document.form1.select1.selectedIndex].value;
                        window.open(location)
                    }
                }
    
                var UG2 = function getUG2() {
                    if (document.form2.select2.options[document.form2.select2.selectedIndex].value != "none") {
                        var location = document.form2.select2.options[document.form2.select2.selectedIndex].value;
                        window.open(location)
                    }
                }
            </script>
            <form action="" name="form1">
                <p class="clear">
                    <select name="select1" style="width: 10.5em">
                        <option selected="selected" value="#">Select a user guide</option>
                        <option value="http://manuals.info.apple.com/en_US/ipad_user_guide.pdf">ipad user guide</option>
                        <option value="http://manuals.info.apple.com/en_US/iphone_user_guide.pdf">iphone user guide</option>
                    </select>
                    <input onclick="getUG1()" type="button" value="Get PDF" />
                </p>
            </form>
            <br />
            <br />
            <form action="" name="form2">
                <p class="clear">
                    <select name="select2" style="width: 10.5em">
                        <option selected="selected" value="#">Select a user guide</option>
                        <option value="http://docs.blackberry.com/en/smartphone_users/deliverables/1202/userguide_bb8330_cdma.pdf">blackberry 8330 user guide</option>
                        <option value="http://cb.vu/unixtoolbox.pdf">unix toolbox</option>
                    </select>
                    <input onclick="getUG2()" type="button" value="Get PDF" />
                </p>
            </form>
        </body>
    
    </html>​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a solution that will allow me to do the following to
We're looking for a solution that will allow us to use HTTPS without encryption.
I'm looking for a solution that will allow my Rails app to render a
I am looking for a C# solution that will allow me to iterate backwards
I'm looking for a simple solution that will be: Easy to integrate Allow multiple
I am looking for a solution that will allow me to do advanced logging:
I am looking for a solution that will allow me to print generic url
I'm using NHibernate and looking for a solution that will allow me to audit
I am looking for some solution for ASP.NET GridView that will allow to resize
I'm looking for a simple Java encryption solution that will allow me to specify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.