Solved

webpage code help needed

Posted on 2013-05-23
3
310 Views
Last Modified: 2013-06-09
I have this code that adds a textbox and submit button on my webpage, it takes whatever you enter into the textbox and goes to a address in this case http://jy*******/yur*****/intranet/ adds your text (let's say AML1) and adds .pdf to the end.

Here is what it would look like in case you didn't follow me

http://jy*******/yur*****/intranet/AML1.pdf

My problem is that if the file dosen't exist on the server you get the standard 404 error, now I know that I could change the 404 error and make it custom however I wanted to know if there was a way to check if that file exists and if not redirect them to a different page.

Here is the code:

<html lang="en">
<head>
<base target="main">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<style type="text/css">
#wrapper {
    width:482px;
    margin:auto;
 }
.container {
    float:left;
    width:195px;
    border:0px double #;
    padding:10px 10px 0;
    font-family:sans-serif;
    color:#3333cc;
    text-align:center;
    background-color:#cf8030;
    margin:0 10px;
 }
.container h1 {
    margin:0 0 10px 0;
    font-size:1em;
 }
.container input {
    margin-bottom:10px;
 }
</style>

<script type="text/javascript">

function init() {

   var kywd=['','KEYWORD/'];
   var df=[];
   f=document.getElementsByTagName('form');
for(c=0;c<f.length;c++) {
   df[c]=document.forms[c];
   df[c].number=c;
   df[c].onsubmit=function() {  
   location.href='http://jy*********/yur*****/intranet/'+kywd[this.number]+df[this.number][0].value+".pdf";
   return false;
   }
  }
 }
   window.addEventListener?
   window.addEventListener('load',init,false):
   window.attachEvent('onload',init);

</script>

</head>
<body>

<div id="wrapper">

<form action="#">
<div class="container">
<h1>Enter Password</h1>
<input type="password">
<input type="submit" value="Submit"/>
</div>
</form>


</div>

</body>
</html>
0
Comment
Question by:KevinSchildt
3 Comments
 
LVL 13

Accepted Solution

by:
AielloJ earned 250 total points
ID: 39191529
KevinSchildt,

That type of error can be caught in several ways.  What type of scripting resources you have will determine how you approach it.

1) You could use AJAX and the XMLHttpRequest.status function to test if the page exists.  This is pretty much a JavaScript only solution.  No scripting language needed.
2) You could use your scripting language (php, etc) to handle this on the server.  This allows more sophisticated handling of things.

Best regards,

AielloJ
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 250 total points
ID: 39191630
Or use a "head" request
0
 
LVL 53

Expert Comment

by:Julian Hansen
ID: 39191723
You can also catch this in the .htaccess file - and redirect it to another location if it does not exist.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now