form is undefined message

E

eric.goforth

Hello,

I'm getting a form undefined when I try to validate a date field. I've
created a much simpler version of my web page that reproduces the
issue, can anyone tell me why I can't access the Text field on my form
like I'm trying to do?

<html>
<head>

<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>


<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
</head>
<body>
<title>Test</title>

<TABLE border="0" cellpadding="0" cellspacing="0">
<table cellpadding="4" cellspacing="4" border="0" width="100%">
<tr>
<td class="bodyMain">
<form method="post" name="form1" onsubmit="javascript:
checkdatefield();" action="">
<tr>
<td>Effective Date:</td>
<td><input tabindex="1" maxlength="50" type="Text" Id="sMyDate"
Name="sMyDate" SIZE="10" value="01-05-2006"></td>
</tr>
</table>

</td>
</tr>
</table>
<table cellpadding="3" cellspacing="0" border="0">
<tr>
<td valign="top" align="left" colspan="4" class="data">

<input type="Button" class="button" name="Cancel"
onClick="window.location='takemeback';" value="Cancel"><input
type="submit" value="Save">

<SCRIPT language="javascript">
function checkdatefield(){

var currDate=new Date() //Get todays date

if (form.sMyDate.value > currDate) //Compare dates
(simplified, the original stuff called a function)

{
if (confirm("Danger Will Robinson Danger!!!"))
alert("yes");
else
alert("no")
}

}

</SCRIPT>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</TD>
</TR>
</TABLE></body>
</html>
 
L

Lee

(e-mail address removed) said:
Hello,

I'm getting a form undefined when I try to validate a date field. I've
created a much simpler version of my web page that reproduces the
issue, can anyone tell me why I can't access the Text field on my form
like I'm trying to do?

<html>
<form method="post" name="form1" onsubmit="javascript:
checkdatefield();" action="">
<input type="submit" value="Save">

<SCRIPT language="javascript">
function checkdatefield(){

var currDate=new Date() //Get todays date

if (form.sMyDate.value > currDate) //Compare dates
(simplified, the original stuff called a function)

1. Remove the massive indentations before posting code.
2. You don't need the "javascript:" label in your onsubmit value.
It doesn't hurt anything, but it doesn't do anything, either.
3. Since you don't have an action, and your onsubmit event handler
doesn't return a value, clicking submit is going to cause the page
to reload. You could change your onsubmit handler code to:
"checkdatefield();return false" to prevent that.
4. There's no global variable in your page named "form".
The correct way to refer to a form that doesn't have a name is:
if (document.forms[0].sMyDate.value ...


--
 
A

ASM

(e-mail address removed) a écrit :
Hello,

I'm getting a form undefined when I try to validate a date field. I've
created a much simpler version

so simpler it is wrong built ...

title has to be in head section

You cant have a form sliced in different sisters tables
(I mean opening form tag in a table and closing one in another)

but the form can content tables and imbricated tables

<table>
<tr>
<td>
<form>
<input ... >
<table>
<tr><td><input ...>
</table>
<table>
<tr><td><input ...>
</table>
</form>
</td>
</tr>
<TABLE border="0" cellpadding="0" cellspacing="0">

Let us take it back from zero :
(date entered in French format: D, M , Y)

<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 >
<TR>
<TD class=bodyMain>
<FORM ACTION="" name=form1 onsubmit="return checkdatefield();">
<TABLE BORDER=1>
<TR>
<TD>Effective Date:</TD>
<TD>
<INPUT NAME=sMyDate id=sMyDate TYPE=text
VALUE="01-05-2006" tabindex=1>
</TD>
</TR>
<TR>
<TD><INPUT TYPE=button NAME=Cancel VALUE="Cancel"
class=button onclick="window.location='takemeback';">
</TD>
<TD><INPUT TYPE=submit NAME=Envoi VALUE="Save"></TD>
</TR>
</TABLE>
<SCRIPT type="text/javascript">
function checkdatefield(){
var currDate=new Date() //Get todays date
alert(currDate);
var effDate = document.form1.sMyDate.value.split('-');
effDate = new Date(effDate[2],effDate[1]-1,effDate[0]);
alert(effDate);
if (effDate < currDate) //Compare dates
{
if (confirm("Danger Will Robinson Danger!!!"))
alert("yes");
else
alert("no")
}
return false;
}
</SCRIPT>
</FORM>
</TD>
</TR>
</TABLE>
 
D

Dr J R Stockton

In comp.lang.javascript message
Let us take it back from zero :
(date entered in French format: D, M , Y)

Don't claim exclusive credit for your nation! All reasonable countries
use D M Y, if they do not prefer Y M D.

var effDate = document.form1.sMyDate.value.split('-');
effDate = new Date(effDate[2],effDate[1]-1,effDate[0]);

Using .split(/\D/) will accommodate at least most European situations.


This might do for all in-range European-style numeric Gregorian AD
dates, without validating the numerical values of Y M D.

S = F.X0.value // source of D M Y date string
R = /\D*(\d+)(\W)(\d+)\2(\d+)\D*/
D = new Date( S.match(R) ? S = S.replace(R, "$4/$3/$1") : NaN )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top