I am currently using a JavaScript code that allows users to jump to a directory by typing its name. Here is how it functions: If the input field is left empty, the user will be directed to a page called "error.html" which displays the message "This field cannot be empty." In case the directory name does not exist, the user will be redirected to "error2.html" with the message "Looks like this page doesn't exist." However, I have encountered an issue. There is a directory named 333, and when I enter the name of this existing directory (333), instead of being redirected to the correct location, I end up on the "error2.html" page. I would greatly appreciate any assistance in fixing the script above.
<form action="javascript:void(0)" name="f1" onsubmit="jump();">
<input type="text" name="k1" value="" placeholder="Enter the name of the directory"/>
<input id="submit" type="submit" name="s1" value="check">
</form>
<script>
function jump() {
var directory = document.f1.k1.value.trim();
if (directory === "") {
window.location.href = 'error.html';
document.f1.k1.focus();
return;
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
window.location.href = directory;
} else {
window.location.href = 'error2.html';
}
}
};
xhttp.open("HEAD", directory, true);
xhttp.send();
}
</script>