Solved

webpage code help needed

Posted on 2013-05-23
3
308 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 51

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 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

20 Experts available now in Live!

Get 1:1 Help Now