Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation 1

Status
Not open for further replies.

coldfused

Technical User
Jan 27, 2001
2,442
US
The javascript:



<script language=&quot;JavaScript&quot;>
<!-- Hide
function validate( form ) {
if ( form.email.value == &quot;&quot; || form.email.value.indexOf('@',0) == -1)
{ alert(&quot;Invalid e-mail address!&quot;);
return false;
}
else return true;
}
--></script>



The Handler:

onSubmit=&quot;return validate(MyForm3)&quot;


Works fine but here is my problem. It only seems to work on one form, on my pages I have two forms as you saw. Made two seperate functions for each one, called from an external .js file. One worked one did not. They were exactly the same minus the different form names and field names pertaining to the function for that particular form. Can you only validate one form on a page?

Also the onSubmit handler is not xhtml compliant.

Any thoughts on the work around guys? I would really like to have these two sign ups on my pages, shows some interactivity if nothing else. Plus I want to highlight my email marketing program by having potential customers sign up and receive mail from me to show them how its done.

I searched google for the fix, but to no good.



csatterwhite@orlandomediasolutions.com
 
I'm not sure bout that one dwarf. The form is handled like this:

<FORM NAME=&quot;MyForm3&quot; METHOD=&quot;POST&quot; ACTION=&quot;onSubmit=&quot;return validate(MyForm3)&quot;>

Which works fine. Just not two on the same page, nor does this handler validate in xhtml.

But off to bed now, you guys drained me in the other thread.

And you might be right about this, will look into it further in the morning.


csatterwhite@orlandomediasolutions.com
 
can i have both ur form tags?

Known is handfull, Unknown is worldfull
 
Also you might try the Javascript forum -- forum216 -- in the future. It's mostly the same crowd but if you get a good answer you'll help future people who are searching for an answer because they're more likely to search it for Javascript help.
 
Hi virt2002
Do you have any <script> tags in the .js file?



____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
The problem I would think is the fact you have two fields named the same in the page.
That will not work out very well

do this and see if it is a solution
change the name of the email field to
<input type=&quot;text&quot; name=&quot;email1&quot;>
and
<input type=&quot;text&quot; name=&quot;email2&quot;>

now just pass the email value with the function so you know what to reference in the function

onSubmit='return validate(&quot;email1&quot;)'

here's the catch. With this type of dynamic form validation in web development
you need to catch the object as itself. forget the form name and use the
getElementById method. It's browser friendly and completely dynamic as anything else is.

so the call as above and the function changes to
function validate(fieldObj) {
alert(document.getElementById(fieldObj).value);

if((document.getElementById(fieldObj).value == &quot;&quot;)||(document.getElementById(fieldObj).value.indexOf('@') == -1)) {
alert(&quot;Invalid e-mail address!&quot;);
return false;
}
else {
return false;
}
}

there's some differences. notice the extra ( ) that can cause syntax errors when they are left out.
mainly with AND operatos though. Teh naming convention. don't use form. I see it all the time and
hate it. form is a tag. you shouldn't use that for a parameter name.

anyhow, next time deffinetely post in the javascript forum.
hope this solves it for you

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top