PDA

View Full Version : whats wrong with this validation?


webmarkart
11-05-2002, 04:05 AM
here's the code I'm using...


<SCRIPT LANGUAGE="JavaScript">
<!--
function validate(form)
{
if (form.NAME.value=="")
{
alert("Please Enter your name");
document.feedback.NAME.focus();
}
else if (form.EMAIL.value=="")
{
alert("Please Enter your email address");
document.feedback.EMAIL.focus();
}
else
{
form.submit();
}
}
//-->
</SCRIPT>
<H1>:Contact Me:</H1>
<P>Here's your chance to tell me why I am right or wrong, or if you have a suggestion for an article.</P>
<FORM>
<FORM ACTION="default.asp?action=contactprocess" METHOD="POST" NAME="feedback"></FORM>
<H2>Name: <INPUT TYPE="text" NAME="NAME" SIZE="25" MAXLENGTH="50">
Email: <INPUT TYPE="text" NAME="EMAIL" SIZE="35" MAXLENGTH="50"></H2>
<P>&nbsp;<P>
<H2>Comment:<BR><TEXTAREA COLS="75" ROWS="7" NAME="COMMENT" ID="COMMENT">Comment database has not been set up yet</TEXTAREA></H2>
<P>
<A HREF="javascript:validate()"><IMG SRC="images/submit.gif" ALT="" WIDTH="79" HEIGHT="21" BORDER="0"></A>
<A HREF="javascript:document.feedback.reset()"><IMG SRC="images/reset.gif" ALT="" WIDTH="79" HEIGHT="21" BORDER="0"></A>
</P>
</FORM>


I keep getting 'NAME' is not an object?!

beetle
11-05-2002, 05:29 AM
The validation looks fine (a bit messy, but fine), it's your HTML that is causing the problem....let's have a look:<FORM>
<FORM ACTION="default.asp?action=contactprocess" METHOD="POST" NAME="feedback"></FORM>
<H2>Name: <INPUT TYPE="text" NAME="NAME" SIZE="25" MAXLENGTH="50">
Email: <INPUT TYPE="text" NAME="EMAIL" SIZE="35" MAXLENGTH="50"></H2>
<P> <P>
<H2>Comment:<BR><TEXTAREA COLS="75" ROWS="7" NAME="COMMENT" ID="COMMENT">Comment database has not been set up yet</TEXTAREA></H2>
<P>
<A HREF="java script:validate()"><IMG SRC="images/submit.gif" ALT="" WIDTH="79" HEIGHT="21" BORDER="0"></A>
<A HREF="java script:document.feedback.reset()"><IMG SRC="images/reset.gif" ALT="" WIDTH="79" HEIGHT="21" BORDER="0"></A>
</P>
</FORM>
As you can see, the form in blue (the one you are trying to access) has no elements, children or anything. I is closed on the same line it is opened. All the form elements are now part of the form in red, which has no name, or any other properties for that matter. So, document.feedback.NAME certainly does not exist, because NAME is not in the feedback form. Strip your HTML of those unecessary FORM tags and you should be a-ok. :D

webmarkart
11-05-2002, 05:47 AM
that was definitely an oversite, but what happened was that I was trying so many things I kept copying and pasting different elements into the page. I didn't have that there the whole time I was trying to get this to work. Anyway I removed the extra form tags and I'm still getting the same error... 'NAME' is not an object

webmarkart
11-05-2002, 05:48 AM
here's the link: www.webmarkart.com/because/default.asp?action=contact

beetle
11-05-2002, 05:56 AM
Well, typically javascript is super case-sensitive, but since name is javascript keyword, that may be the problem. Also, form is a keyword as well. Let's change a couple things up... function validate(f)
{
if (f.elements['NAME'].value=="")
{
alert("Please Enter your name");
f.elements['NAME'].focus();
}
else if (f.EMAIL.value=="")
{
alert("Please Enter your email address");
f.EMAIL.focus();
}
else
{
f.submit();
}
}
Try that, and let me know.

P.S. For what it's worth, I've written a pretty decent form validation script, fValidate (http://www.peterbailey.net/fValidate)

webmarkart
11-05-2002, 06:12 AM
I checked out your validation script and its very impressive. Its much more indept than I am looking for though. I just need a really simple script. I've used this same validation template for a while and I've never had the problems I am now... anyway I finally got it to work. Thanks for the advice