PDA

View Full Version : submit numbers in edit box to HTML page???


doubleT
08-14-2002, 04:16 AM
Hello all..

Can any one help me to write a javascript that when some one type in the numbers such as 1915, and it will go to 1915.html?

I want the people have to type 4 digits numbers, and only accept from 1920 to 2040 only! Other numbers such as 1900 will popup a messages and said "No Numbers Found or something like that"..

Can any one do that, like with a edit box with the submit button?

glenngv
08-14-2002, 04:29 AM
<html>
<head>
<script language="javascript">
function check(){
no=document.f.num.value;
if (!isNaN(no)){
no = parseInt(no,10);
if (no>=1920 && no<=2040){
location.href=no+".html";
return;
}
}
alert("Please type a number between 1920 to 2040.");
document.f.num.focus();
document.f.num.select();
}
</script>
</head>
<body>
<form name="f">
Please enter a 4-digit number:
<input name="num" maxlength="4"><br>
<input type="button" value="Open" onclick="check()">
</form>
</body>
</html>

doubleT
08-14-2002, 05:56 AM
Thx glenngv, that works!

I have one more question..

How do I make it go to a folder then num.html such as folder/1921.html


location.href=cfolder/+no+".html";
That will get a NaN.html when press Open

location.href=folder/ no+".html";
same thing..

glenngv
08-14-2002, 06:05 AM
location.href="folder/"+no+".html";

doubleT
08-14-2002, 06:57 PM
thank you. it works

doubleT
08-14-2002, 07:02 PM
Is there a way I can insert it in a CSS or so when I edit it in the css file. IT will be works on all my html pages.

All I need is to put this.. and it will show the above HTML:
<link href="filename.css" rel="stylesheet">

I know it something like that. but I don't know how to say it...

Please help me...:confused:

glenngv
08-15-2002, 04:23 AM
since you will use it to some of your pages, i edited it so that it will be generic:

save it in a separate file with extension .js (don't include script tag)

function check(objNo){
no=objNo.value;
if (!isNaN(no)){
no = parseInt(no,10);
if (no>=1920 && no<=2040){
location.href=no+".html";
return;
}
}
alert("Please type a number between 1920 to 2040.");
objNo.focus();
objNo.select();
}




then in your html pages:
<html>
<head>
<script language="javascript" src="validation.js"></script>
</head>
<body>
<form>
<input name="num" maxlength="4"><br>
<input type="button" value="Open" onclick="check(this.form.num)">
</form>
</body>
</html>

change validation.js to the name of your js file and num to appropriate name of textbox.

doubleT
08-15-2002, 07:08 AM
It works, but I need it to target my html file into a directory/folder
location.href=folder/"+no+".html;
I will get -1.#IND.

location.href="folder/"+no+".html;
I will get error..

:rolleyes:

glenngv
08-15-2002, 07:34 AM
i thought this already works:
location.href="folder/"+no+".html";

or do you mean like this:
location.href="directory/folder/"+no+".html";



Originally posted by doubleT
It works, but I need it to target my html file into a directory/folder
location.href=folder/"+no+".html;
I will get -1.#IND.

location.href="folder/"+no+".html;
I will get error..

:rolleyes:

doubleT
08-16-2002, 01:38 AM
It is already works for one page, but inside the filename.js won't work I use those codes..

glenngv
08-16-2002, 02:01 AM
Originally posted by doubleT
It is already works for one page, but inside the filename.js won't work I use those codes..

can you post the html and js codes?

doubleT
08-16-2002, 02:19 AM
Here is the HTML...
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Student Section</title>
<link href="main_files/style.css" rel="stylesheet">
<script language="javascript" src="classmates/classmate.js"></script>
</head>
<body>
<form>
<p align="center">&nbsp;
<input name="num" maxlength="4" size="10" style="background-color:#FFCC00" style="color:#0000FF"><input type="button" value="GO" onclick="check(this.form.num)" style="background-color:#0000FF" style="color:#FFFF00">
<br>
</form></body>
</html>

Here is the JS file...


function check(objNo){
no=objNo.value;
if (!isNaN(no)){
no = parseInt(no,10);
if (no>=1910 && no<=2049){
location.href="classmates/"+no+".html;
return;
}
}
alert("Input year from 1910 to 2049");
objNo.focus();
objNo.select();
}

glenngv
08-16-2002, 02:57 AM
can you also post the directory structure of all your pages, like where the 1910-2049.html pages are, the .js files, etc

doubleT
08-16-2002, 06:16 AM
All mine HTML and js file are in the classmates folder..

glenngv
08-19-2002, 01:21 AM
if your html and js files are all in the classmates folder, then you should not have specified the classmates folder in the script tag and in location.href. It should be these:

<script language="javascript" src="classmate.js"></script>

location.href=+no+".html;