Open a pdf by entering reference

H

Horness

Hi All,

We're in the process of re-writing the Intranet at work, and my javascript
knowledge could be written on the back of a post card. ;-)

Can any of you point me in the direction of some code that would enable a
form to open a specific pdf file? Details are below.

--------------------
All of our purchase orders are saved back to pdf files. Each pdf has the
prefix "PO_" followed by the po reference, then the file extension ".pdf".
For example, our file would be called "PO_12345M.pdf".
Each set of files is archived into years (folders are called 2003, 2004,
2005 etc.) so it will probably need a drop down box to select year, unless
it can search through all the folders.

The visitor should only need to enter the PO reference, and the code puts
the "PO_" and the ".pdf" on the end of it, and hey presto Acrobat opens with
the PO, or you get an error dialog if the file cannot be found.
--------------------

Any help appreciated, as is any code I can butcher to get this working.
Major brownie points this end. ;-)

Happy New Year everyone.

Horness
 
M

McKirahan

Horness said:
Hi All,

We're in the process of re-writing the Intranet at work, and my javascript
knowledge could be written on the back of a post card. ;-)

Can any of you point me in the direction of some code that would enable a
form to open a specific pdf file? Details are below.

--------------------
All of our purchase orders are saved back to pdf files. Each pdf has the
prefix "PO_" followed by the po reference, then the file extension ".pdf".
For example, our file would be called "PO_12345M.pdf".
Each set of files is archived into years (folders are called 2003, 2004,
2005 etc.) so it will probably need a drop down box to select year, unless
it can search through all the folders.

The visitor should only need to enter the PO reference, and the code puts
the "PO_" and the ".pdf" on the end of it, and hey presto Acrobat opens with
the PO, or you get an error dialog if the file cannot be found.
--------------------

Any help appreciated, as is any code I can butcher to get this working.
Major brownie points this end. ;-)

Happy New Year everyone.

Horness


Will this work for you? Watch for word-wrap.

This presumes that the "year" folders are under the folder that contains
this page.

The current year is the default and there is minimal validation.

Remove the "alert()" after testing.

<html>
<head>
<title>pdfinder.htm</title>
<script type="text/javascript">
function openPDF() {
var year = document.getElementById("Year").value;
var data = document.getElementById("Data").value;
if (data.length != 6) return;
var file = year + "\\PO_" + data + ".pdf";
alert(file); // remove after testing
window.open(file,"pdf","");
}
</script>
</head>
<body>
<form>
<select name="Year" id="year">
<option value="2005" selected>2005
<option value="2004">2004
<option value="2003">2003
</select>
<input type="text" name="Data" id=""Data" size="6" maxlength="6">
<input type="button" value="Open PDF" onclick="openPDF()">
<input type="reset" value="Reset">
</form>
</body>
</html>
 
H

Horness

That works perfectly, absolutely fantastic!

Many (MANY!) thanks for that - it's much appreciated.

<BIG GRIN>

Horness
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top