473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

strange error

Hi Gurus

The page below has a strange error. It seems to be working very well, just
when you enter 8 or 9 for day, month or year then you get an error. I
really have no idea where that is coming from. Can you help?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Online availability</TITLE>
<META NAME="keywords" CONTENT="Online availability" >
<META NAME="description" CONTENT="Online availability" >
<META NAME="Author" CONTENT="www.sunnysideup.co.nz" >
<SCRIPT TYPE="text/javascript">
<!--
function padLeft(str, pad, count) {
while(str.length<count)
str=pad+str;
return str;
}

function check(el, field) {
//controller
var result={error:""};
for(var ii=2; ii<arguments.length; ii++)
if((result=singleCheck(el, field, arguments[ii])).error)
break;
return result;

//single check
function singleCheck(el, field, type) {
var result={error:""};
switch(type) {
case "empty" :
if(/^\s*$/.test(el.value)) {
result.error="field "+field+" : should not be empty.";
}
break;
case "2num" :
if(!/^\d+$/.test(el.value)) {
result.error="field "+field+" : should contain only numbers.";
} else {
el.value=
padLeft(el.value.replace(/^\d+(\d\d)$/,"$1"), "0", 2);
}
break;
}

if(el.style)
el.style.color = result.error ? "#c00" : "";

return result;
}
}

function validate(form){
var a=[], msg=[], index=1;

// re-test the fields
a[a.length]=check(form.elements[0], "foo1", "empty", "2num");
a[a.length]=check(form.elements[1], "foo2", "empty", "2num");
a[a.length]=check(form.elements[2], "foo3", "empty", "2num");

//analyse the tests
for(var ii=0; ii<a.length; ii++)
if(a[ii].error)
msg[msg.length]=(index++)+" - "+a[ii].error;

//alert the message, if any
if(msg.length)
alert(msg.join("\n"));

//handle form's submission
return !msg.length;
}

function valid(form) {
var e = 0

var field = form.year;
var useryear = parseInt(field.value);
if (!useryear) {
alert("You must indicate a year (e.g. 04 or 05).");
field.focus();
field.select();
e = e + 1
} else if (useryear >= 4) {

} else {
alert("You should enter a year in the future, for example 05, you
entered " + useryear);
field.focus();
field.select();
e = e + 1
}

var field = form.month;
var usermonth = parseInt(field.value);
if (!usermonth) {
alert("You must indicate a month (e.g. 12 or 03).");
field.focus();
field.select();
e = e + 1
} else if (usermonth <= 12) {

} else {
alert("You should enter a month between 01 and 12, you entered " +
usermonth);
field.focus();
field.select();
e = e + 1
}

var field = form.day;
var userday = parseInt(field.value);
if (!userday) {
alert("You must indicate a day (e.g. 10 or 03).");
field.focus();
field.select();
e = e + 1
} else if (userday <= 31) {

} else {
alert("You should enter a day between 01 and 31, you entered " +
userday);
field.focus();
field.select();
e = e + 1
}
document.location.href='#' + form.day.value + form.month.value +
form.year.value;
}
-->

</SCRIPT>
<STYLE TYPE="text/css">
BODY, TABLE, TD, H1 {font-family: verdana, arial, helvetica, tahoma,
geneva;}
DIV.content { }
TABLE{border: 3px solid #CCCCCC; WIDTH: 406px; font-size: 10px;
margin-top: 100px; margin-bottom: 1200px;}

/*search table */
H1 {padding: 5px; text-align: center; background-color: #FFCF1B;
font-size: 12px; margin: 0px; color: white;}
TD.W400H20E8c {width: 400px; height: 20px; background-color: #E8E8E8;
text-align: center;}
TD.W50H40E8r {width: 50px; height: 40px; text-align:
right;background-color: #e8e8e8;}
TD.W400H40E8c {width: 400px; Height: 40px; background-color: #CCCCCC;
text-align: center;}
TD.W450H40E8 {width: 450px; height: 40px; background-color: #e8e8e8;}
input.date {width: 20px; height: 20px; border: 1px solid #FFCF1B;}
input.go {width: 400px; height: 20px; border: 1px solid #FFCF1B;}

/*data table */
TD.f {Height: 20px; background-color: #E8E8E8;}
TD.c {Height: 20px; background-color: #E8E8E8; text-align: center;}
TD.h {Height: 20px; background-color: #FFCF1B; text-align: center;}
</STYLE>
</HEAD>
<BODY STYLE="background-color: #FFFFFF"><DIV ALIGN=CENTER CLASs=content>
<FORM>
<TABLE CELLSPACING=0 CELLPADDING=0 CLASS=s>
<TR><Td COLSPAN=2 class=W400H20E8c><H1>SEARCH FOR AVAILABILITY - ENTER
DATE</H1></TD></TR>
<TR><TD CLASS=W50H40E8r><Input value=00 type=text name="day" SIZE=1
onblur="check(this, 'foo1', 'empty', '2num')" CLASS=date></TD><TD
CLASS=W450H40E8>&nbsp;&nbsp;day (e.g. 02 or 23)</TD></TR>
<TR><TD CLASS=W50H40E8r><Input value=00 type=text name="month" SIZE=1
onblur="check(this, 'foo1', 'empty', '2num')" CLASS=date></TD><TD
CLASS=W450H40E8>&nbsp;&nbsp;month (e.g. 03 or 12)</TD></TR>
<TR><TD CLASS=W50H40E8r><Input value=00 type=text name="year" SIZE=1
onblur="check(this, 'foo1', 'empty', '2num')" CLASS=date></TD><TD
CLASS=W450H40E8>&nbsp;&nbsp;year (e.g. 04 or 05)</TD></TR>
<TR><TD COLSPAN=2 class=W400H20E8c><INPUT TYPE="button" VALUE="SEARCH"
onClick="return valid(form)" CLASS=go></TD></TR>
</TABLE>
</FORM>
<TABLE CELLSPACING=0 CELLPADDING=5 CLASS=d BORDER=1>
<TR><TD class=h>Day</TD><TD class=h>Room 1</TD><TD class=h>Room
2</TD></TR>
<TR><TD class=f><A NAME=110305></A>11 March 2005</TD><TD
class=c>3</TD><TD class=c>3</TD></TR>
<TR><TD class=f><A NAME=120305></A>12 March 2005</TD><TD
class=c>3</TD><TD class=c>3</TD></TR>
<TR><TD class=f><A NAME=130305></A>13 March 2005</TD><TD
class=c>3</TD><TD class=c>3</TD></TR>
<TR><TD class=f><A NAME=140305></A>14 March 2005</TD><TD
class=c>3</TD><TD class=c>3</TD></TR>
<TR><TD class=f><A NAME=150305></A>15 March 2005</TD><TD
class=c>3</TD><TD class=c>3</TD></TR>
<TR><TD class=f><A NAME=160305></A>16 March 2005</TD><TD
class=c>3</TD><TD class=c>3</TD></TR>
<TR><TD class=f><A NAME=170305></A>17 March 2005</TD><TD
class=c>3</TD><TD class=c>3</TD></TR>
</TABLE>
<BR>last updated: 11 November 2004, 13:50
</BODY>
</HTML>
Jul 23 '05 #1
6 1760
WindAndWaves wrote:
The page below has a strange error. It seems to be working very well, just
when you enter 8 or 9 for day, month or year then you get an error. var useryear = parseInt(field.value);


parseInt can actually take two arguments; the first one is the string to
be converted to an integer (with specific conversion rules), and the
second one (which is optional) is the base to be used. If you omit the
second argument, then the base is guessed by the function: strings
starting by "0x" are hexadecimal, strings starting by "0" are octal and
the rest is decimal.

In your case, since your numbers are starting with a "0", they're
assumed to be octal - and in an octal base "08" or "09" do not exist.
You therefore need to force the base:

parseInt(field.value, 10);

Also, don't forget to test the format of the string with the regexps
before actually calling parseInt!

<URL:http://jibbering.com/faq/#FAQ4_12>
<URL:http://www.jibbering.com/faq/faq_notes/type_convert.html#tcPrIntRx>
Regards,
Yep.
Jul 23 '05 #2
Lee
WindAndWaves said:

Hi Gurus

The page below has a strange error. It seems to be working very well, just
when you enter 8 or 9 for day, month or year then you get an error.


No need to read further.
Wherever you're using parseInt(), add the radix argument:

parseInt(whatever.value,10);

Numbers with leading zeros are assumed to be octal, unless you tell
parseInt to treat them as base 10.

08 and 09 are invalid octal values.

Jul 23 '05 #3

"Lee" <RE**************@cox.net> wrote in message
news:cm*********@drn.newsguy.com...
WindAndWaves said:

Hi Gurus

The page below has a strange error. It seems to be working very well, justwhen you enter 8 or 9 for day, month or year then you get an error.


No need to read further.
Wherever you're using parseInt(), add the radix argument:

parseInt(whatever.value,10);

Numbers with leading zeros are assumed to be octal, unless you tell
parseInt to treat them as base 10.

08 and 09 are invalid octal values.

THANK YOU
Jul 23 '05 #4

"Yann-Erwan Perio" <y-*******@em-lyon.com> wrote in message
news:41**********************@news.free.fr...
WindAndWaves wrote:
The page below has a strange error. It seems to be working very well, just when you enter 8 or 9 for day, month or year then you get an error.

var useryear = parseInt(field.value);


parseInt can actually take two arguments; the first one is the string to
be converted to an integer (with specific conversion rules), and the
second one (which is optional) is the base to be used. If you omit the
second argument, then the base is guessed by the function: strings
starting by "0x" are hexadecimal, strings starting by "0" are octal and
the rest is decimal.

In your case, since your numbers are starting with a "0", they're
assumed to be octal - and in an octal base "08" or "09" do not exist.
You therefore need to force the base:

parseInt(field.value, 10);

Also, don't forget to test the format of the string with the regexps
before actually calling parseInt!

<URL:http://jibbering.com/faq/#FAQ4_12>
<URL:http://www.jibbering.com/faq/faq_notes/type_convert.html#tcPrIntRx>
Regards,
Yep.

THANK YOU
Jul 23 '05 #5
JRS: In article <AO******************@news.xtra.co.nz>, dated Sun, 31
Oct 2004 10:35:13, seen in news:comp.lang.javascript, WindAndWaves
<ac****@ngaru.com> posted :
The page below has a strange error. It seems to be working very well, just
when you enter 8 or 9 for day, month or year then you get an error. I
really have no idea where that is coming from. Can you help?


Did we not already advise you to read the newsgroup FAQ?

<FAQENTRY> FAQ 4.12 needs a link to FAQ 4.21 </FAQENTRY>

There seems no point in demanding, or even allowing, leading zeroes in
Y M D if they are entered as separate fields. If the output needs them,
the code should provide them.

It is more logical to have the fields in Y M D order; the current
settings of Y M can then reasonably be used to set an appropriate upper
limit on D.

Four-digit years are always better; for the present, you could put 20
before the box.

Function parseInt(X, 10) is only needed (AFAIR) if X may contain non-
whitespace after the number.

You use "numbers" to mean "digits". '05' and '23' are numbers, but are
not digits.

It's not clear to me whether the year should be in the future, or the
date; apparently you allow anything after 2004-01-01.

When posting code to News, you must not let your system break lines. If
you cannot control your posting agent, you must make *all* of your lines
sufficiently short.

You presumably should check that the date is valid, and not such as Feb
30 or Jun 31 - see FAQ, section 3.2, and below.

It accepts a month of -3, because you test for !=0 and <=12.

Parts are repetitive; use a common function, with parameters.

You don't need such detailed error messages; put "future year" or
"future date" on the form.

The code is very much longer than is needed to enter, and validate, a
future date. Remember that it all has to be downloaded by the user.

I'd use a single field, asking for entries as "Y M D", numeric, e.g.
2004 6 12; pattern-validate and split with a RegExp using \D+ for
separators; put into a Date Object and check M & D for value validation,
check against new Date() or something calculated from that for date
range validity ("future"), and use finally

document.location.href='#' + (Y*100+M+1)*100+D

where Y M D are the validated numbers.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:m5**************@merlyn.demon.co.uk...
JRS: In article <AO******************@news.xtra.co.nz>, dated Sun, 31
Oct 2004 10:35:13, seen in news:comp.lang.javascript, WindAndWaves
<ac****@ngaru.com> posted :
The page below has a strange error. It seems to be working very well, justwhen you enter 8 or 9 for day, month or year then you get an error. I
really have no idea where that is coming from. Can you help?
Did we not already advise you to read the newsgroup FAQ?

<FAQENTRY> FAQ 4.12 needs a link to FAQ 4.21 </FAQENTRY>

There seems no point in demanding, or even allowing, leading zeroes in
Y M D if they are entered as separate fields. If the output needs them,
the code should provide them.

It is more logical to have the fields in Y M D order; the current
settings of Y M can then reasonably be used to set an appropriate upper
limit on D.

Four-digit years are always better; for the present, you could put 20
before the box.

Function parseInt(X, 10) is only needed (AFAIR) if X may contain non-
whitespace after the number.

You use "numbers" to mean "digits". '05' and '23' are numbers, but are
not digits.

It's not clear to me whether the year should be in the future, or the
date; apparently you allow anything after 2004-01-01.

When posting code to News, you must not let your system break lines. If
you cannot control your posting agent, you must make *all* of your lines
sufficiently short.

You presumably should check that the date is valid, and not such as Feb
30 or Jun 31 - see FAQ, section 3.2, and below.

It accepts a month of -3, because you test for !=0 and <=12.

Parts are repetitive; use a common function, with parameters.

You don't need such detailed error messages; put "future year" or
"future date" on the form.

The code is very much longer than is needed to enter, and validate, a
future date. Remember that it all has to be downloaded by the user.

I'd use a single field, asking for entries as "Y M D", numeric, e.g.
2004 6 12; pattern-validate and split with a RegExp using \D+ for
separators; put into a Date Object and check M & D for value validation,
check against new Date() or something calculated from that for date
range validity ("future"), and use finally

document.location.href='#' + (Y*100+M+1)*100+D

where Y M D are the validated numbers.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE

4 © <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,

links.
Dear John

Thank you for your comments.

Let me note:
a. I am really useless with javascript. I am a complete novice.
b. your idea of one field is great, but I would like to make it easy for my
users.
c. if i knew how to use javascript then I would write something simple, but
I have no idea where to start.
d. I would follow up on all your comments if only i knew how to.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
0
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
6
by: Gary | last post by:
I have an application that has been working just fine for a couple of years. It queries a SQL database and returns some formatted data back to the client. I have a new client, who has a larger...
5
by: Nathan Sokalski | last post by:
When I view my index.aspx page any time after the first time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize)...
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
1
by: JoReiners | last post by:
Hello, I have a really strange problem. I'm unable to figure it out on my own. I parse very simple xml documents, without any check for their form. These files look very similar and are encoded...
11
by: Mike C# | last post by:
Hi all, I keep getting a strange error and can't pin it down. The message is: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's...
3
by: Shelly | last post by:
I am encountering two strange problems. First one: I get a "server misconfiguration error", but only sometimes. It occurs on the first screen that accesses the database on a submit. This error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.