?
Solved

webpage code help needed

Posted on 2013-05-23
3
Medium Priority
?
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
AielloJ earned 750 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 750 total points
ID: 39191630
Or use a "head" request
0
 
LVL 58

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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 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