Click to See Complete Forum and Search --> : date validation.


seid
09-12-2003, 01:16 PM
hi i have a problem. i'm trying to validate user month input.
so i first check for number in separate javascript and then i check for values less than 13.
what am i doing wrong?????

<TITLE> Letting Only Numbers Pass to a Form Field</TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function ckNumber(evt){
evt=(evt) ? evt : window.event
var charCode = (evt.which) ? evt.which : evt.keyCode
if( charCode > 31 && (charCode < 48 || charCode > 57 )){
status = "This field accepts month values only."
return false
}
status = ""
return true
}
function ckMonth()
{
var m=(document.form1.month.value)
var error=0;
if (m>13){error=1}
if (error>0)
{
alert(m + "is not a valid month.")
return false;
}
return true
document.write('******')

}

</SCRIPT>
</HEAD>

<BODY>
<H1> Letting Only valid month values</H1>
<HR>
<FORM name=form1 onSubmit="return false">
Enter a month: <INPUT TYPE="text" size="2" NAME="month"
onKeyPress="return ckNumber(event)" onLostFocus="return ckMonth()">
</FORM>
</BODY>
</HTML>

Charles
09-12-2003, 01:24 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<form action="">
<div>
<label>Month<input type="text" onchange="this.value = parseInt(this.value); if (isNaN (this.value) || Number(this.value) > 10 || Number(this.value < 1)) {alert('That would not appear to be a valid entry'); this.value = ''; this.focus()}"></label>
</div>
</form>