Forum Moderators: open
I was wondering if I can get a form to link to a certain page, if a certain number is input into the form.
For example, if a person was to input number ‘1234’ can the form pick this up and navigate to a page, especially for number ‘1234’?
And if they input any other number, I’d like the form to pick up on the fact that its not number ‘1234’ and then navigate to a different page that says ‘number not found’.
I am trying to avoid using a database, as I dont know a lot about them.
Many Thanks for your help
Marc.
IMHO, your solution would be a javascript with an if statement. This would an onclick event. A real short example would be something like this:
In the submit button -
onclick="checkField()"
In the <head> a script to the effect -
<script type="text/javascript">
function checkField() {
if (document.form.FIELDNAME.value == 1234){
window.location=URL
}
else { window.location=URL
}
}
</script>
Mind you, I am not an expert in writing scripts, but I think you get the idea. I am sure someone else can help. You may want to post your question in the javascript forum. I do know this, you can use multiple 'if' statements within the script so you could do several URL variations.
Marshall
You have this:
<form method="post" action="pagefinder.cgi">
<p><label for="page_num">Enter page number</label>
<input type="text" name="page_num" id="page_num"></p>
<p>Input type="submit" value="Go To Page">
</form>
In pagefinder.cgi (or .php, .asp) the logic is pretty simple:
- Read and parse the input, get the value of page_num
Example: $page = $FORM{'page_num'};
Check if the file exists. If you use extensions,
$page+= '.html';
if (-f "$page") {
Here you either REDIRECT to the page or slurp it up and output it right from the script
}
else {
print "content-type: text/html\n\n";
print "page not found";
(It would be useful here to just print another copy of the searching form so the user can just search again)
}
This makes your process not dependent on Javascript, which makes it more reliable.