Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-18-2007, 05:41 AM   PM User | #1
voland
New to the CF scene

 
Join Date: Dec 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
voland is an unknown quantity at this point
Wanting a Javascript way of navigating/linking by user entering numbers

Problem as follows. I'm sure the solution is fairly straightforward; I'm a newcomer to Javascript:

I have 75 files which I want accessed from one menu link. Each file is referenced by a number, so for instance "OD_01_PC.htm" can be referred to as "01" as far as the user is concerned; "OD_02_CT.htm" can be referred to as "02", and so forth: The file names vary, but each is given a double digit integer reference number.

I could do it as a jump menu - however the menu would end up being too awkwardly long for the user to scroll through. What I want is a form field where the user can simply enter "63" for instance, and be taken to the corresponding file ("OD_63_PF.htm"), after clicking a "go" button.

I am not looking for the most efficient code. The validation need not be complicated: If the user enters anything other than 01-75 or 0-9 --- the field should simply be cleared on clicking "go". User entry of "9" should be treated the same as user entry of "09".

Any help would be much appreciated.

"voland"
voland is offline   Reply With Quote
Old 12-18-2007, 08:03 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here you are:-

<form name = "myform">
<input type = "text" name = "inBox" size = "2" maxlength = "2">
<input type = "button" value = "GO" onclick = "jump()">
</form>

<script type = "text/javascript">

function jump() {
val = document.myform.inBox.value;
val = parseInt(val);
if (!/\d{1,2}/.test(val)) {
alert ("Invalid Entry! Only numbers are allowed!");
document.myform.inBox.value = "";
document.myform.inBox.focus();
return false;
}
if (val <1 || val >75) {
alert ("Invalid Entry! Must be in range 1 to 75");
document.myform.inBox.value = "";
document.myform.inBox.focus();
return false;
}
if (val <=9) {
val = "0" + val;
}
val = "OD_" + val +"_CT.htm";
alert (val); // delete after testing
window.location = val;
}
</script>

Our advice and assistance is packaged by intellectual weight and not by volume. The contents may possibly settle in transit. E&OE

Last edited by Philip M; 12-18-2007 at 01:33 PM.. Reason: improved
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:25 AM.


Advertisement
Log in to turn off these ads.