473,781 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="descripti on" CONTENT="Online availability" >
<META NAME="Author" CONTENT="www.su nnysideup.co.nz " >
<SCRIPT TYPE="text/javascript">
<!--
function padLeft(str, pad, count) {
while(str.lengt h<count)
str=pad+str;
return str;
}

function check(el, field) {
//controller
var result={error:" "};
for(var ii=2; ii<arguments.le ngth; ii++)
if((result=sing leCheck(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="f ield "+field+" : should not be empty.";
}
break;
case "2num" :
if(!/^\d+$/.test(el.value) ) {
result.error="f ield "+field+" : should contain only numbers.";
} else {
el.value=
padLeft(el.valu e.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.ele ments[0], "foo1", "empty", "2num");
a[a.length]=check(form.ele ments[1], "foo2", "empty", "2num");
a[a.length]=check(form.ele ments[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.locati on.href='#' + form.day.value + form.month.valu e +
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;backgroun d-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="backgrou nd-color: #FFFFFF"><DIV ALIGN=CENTER CLASs=content>
<FORM>
<TABLE CELLSPACING=0 CELLPADDING=0 CLASS=s>
<TR><Td COLSPAN=2 class=W400H20E8 c><H1>SEARCH FOR AVAILABILITY - ENTER
DATE</H1></TD></TR>
<TR><TD CLASS=W50H40E8r ><Input value=00 type=text name="day" SIZE=1
onblur="check(t his, 'foo1', 'empty', '2num')" CLASS=date></TD><TD
CLASS=W450H40E8 >&nbsp;&nbsp;da y (e.g. 02 or 23)</TD></TR>
<TR><TD CLASS=W50H40E8r ><Input value=00 type=text name="month" SIZE=1
onblur="check(t his, 'foo1', 'empty', '2num')" CLASS=date></TD><TD
CLASS=W450H40E8 >&nbsp;&nbsp;mo nth (e.g. 03 or 12)</TD></TR>
<TR><TD CLASS=W50H40E8r ><Input value=00 type=text name="year" SIZE=1
onblur="check(t his, 'foo1', 'empty', '2num')" CLASS=date></TD><TD
CLASS=W450H40E8 >&nbsp;&nbsp;ye ar (e.g. 04 or 05)</TD></TR>
<TR><TD COLSPAN=2 class=W400H20E8 c><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 1798
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.c om/faq/faq_notes/type_convert.ht ml#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(whatev er.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.c om...
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(whatev er.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.c om/faq/faq_notes/type_convert.ht ml#tcPrIntRx>
Regards,
Yep.

THANK YOU
Jul 23 '05 #5
JRS: In article <AO************ ******@news.xtr a.co.nz>, dated Sun, 31
Oct 2004 10:35:13, seen in news:comp.lang. javascript, WindAndWaves
<ac****@ngaru.c om> 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.locati on.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6

"Dr John Stockton" <sp**@merlyn.de mon.co.uk> wrote in message
news:m5******** ******@merlyn.d emon.co.uk...
JRS: In article <AO************ ******@news.xtr a.co.nz>, dated Sun, 31
Oct 2004 10:35:13, seen in news:comp.lang. javascript, WindAndWaves
<ac****@ngaru.c om> 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.locati on.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demo n.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
8927
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 onclick="javaScript:alert('document.forms(0)='+document.forms(0)); parent.myFunc(document.forms(0));" type="button" value="Open" name="Button" ID="Button"> The strange part is that the debug alert says that the document.forms(0) is an object så all seem to be well. But...
25
3744
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 machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
0
328
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 files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f 16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be found
6
1700
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 database than any of our previous customers. For example, the query to build the datatable now takes about 2 minutes instead of one minute or less. This is a third party database we are integrating with. He is getting very strange results. For...
5
1737
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) +313 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +201 System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState) +263
0
3574
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 requests database, and query execution time exceeds 30 seconds, the following error reported: ===
11
2598
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 temperatures. T = 20 degrees at all times.... The 2D T-array looks like this:
1
1557
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 in UTF-8. Now minidom is always able to parse these files with minidom.parse("file") . Now when fetching I use this expression: xmldoc.getElementsByTagName('DocNumb').firstChild.data.encode('latin1')
11
2501
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 support team for more information. However I'm not purposely requesting that the Runtime terminate in an "unusual way." The line that is causing me headaches is:
3
1837
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 is intermittent -- sometimes it happens and sometimes not from the same screen with the same data. Here is the error:
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.