I think the only way to do that would be to have a custom server side 404 not found file for that folder that includes a slightly delayed redirect to the form page. I'm not sure how that would be done, but it could probably be worked out. But assuming the modifiedUrl is the actual page you are going to and not a script (you didn't really answer that question but seem to imply that it is a page), you could rather easily remain on the form page unless an existing page's number were entered into it:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<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"></style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript">
function init(){
var df=document.forms[0];
df[0].focus();
df[1].onclick=function() {
if(!/^\d{5}$/.test(df[0].value)) { // requires a 5 digit number, otherwise:
alert('Please Enter Only the Correct 5 Digit Number');
df[0].focus(); // focus on the text input again
return; }
// if it was a 5 digit number:
var modifiedUrl=df[0].value + '.htm';
$.ajax({
url: modifiedUrl,
cache: false,
success: function(){ // if the page exists:
//alert(modifiedUrl); // this alert is optional, remove it and if the right number is entered the person will go directly to the page
location.href=modifiedUrl; // go to it
},
error: function(e){ // if it's a 404 or other problem
if(e.status === 404){
alert("Page not found. Please make sure you've entered the correct 5 digit number.");
} else {
alert("That page is currently unavailable. Please make sure you've entered the correct 5 digit number or try again later.");
}
df[0].focus(); // focus on the text input again
}
});
} }
if(window.addEventListener){
window.addEventListener('load',init,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',init);
} }
</script>
</head>
<body>
<form action="#">
<div>
<input type="text">
<input type="button" value="add text to a url">
</div>
</form>
If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.
Bookmarks