/    Sign up×
Community /Pin to ProfileBookmark

Using dropdown menu to select what to download

Hi All.

I posted on here yesterday but somehow my post isnt appearing. So here goes again. I am new to these forums and also new to javascript so probably made some glaring errors..be gentle with me.

so i am trying to acheive the following.

create a window with a dropdown menu in it, which has a list of options in it (obviously). You then select the option you require (which links to a pdf) and click on a button to open in a new window, or to save the file locally, to save loading time into pdf viewer. There is a third button to close this window.

My code so far works great opening the pdf in a new window, but alas i cannot get it to use the same file to save as locally.

Any help, suggestions or otherwise greatly appreciated.

Code so far..

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+”.location='”+selObj.options[selObj.selectedIndex].value+”‘”);
if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(“?”))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

//–>
</script>
</head>

<body>
<p><font size=”2″ face=”Arial, Helvetica, sans-serif”><img src=”images/Logo.gif” width=”150″ height=”63″></font></p>
<p><font size=”2″ face=”Arial, Helvetica, sans-serif”>Select the pdf you wish
to view or save. Clicking View opens PDF in a new browser window.</font></p>
<p><font size=”2″ face=”Arial, Helvetica, sans-serif”>
<select name=”menu2″ size=”1″>
<option Value=”menujumper.htm” selected>Choose PDF to open..

<option value=”document1.pdf”>option1
<option value=”document2.pdf”>option2
<option value=”documentn.pdf”>optionn
</select>
<input type=”button” name=”Button2″ onClick=”MM_jumpMenuGo(‘menu2′,’window.open()’,1)” value=”View”>
</font></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; </p>
<p align=”right”><font size=”2″ face=”Arial, Helvetica, sans-serif”>
<input type=”button” name=”Button4″ value=”Close Window” onClick=”javascript:window.close()”>
</font></p>
<p>&nbsp;</p>
</body>
</html>

Thanks for looking if you got this far.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 31.2008 — Either zip the pdf to force a download or use a server side directive to force the download.

You can not open a file and download from the same file just using JavaScript/html.

Example #1 shows this using PHP: http://nz2.php.net/header
×

Success!

Help @milesuk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...