form validation w/Javascript

surreal5335

New Member
Messages
28
Reaction score
0
Points
0
I have email form created with the javascript validation already coded. When I click on the submit button no alert boxes pop to warn me I dont have the fields entered. Can anybody help me to get the JS to take action when the submit button is clicked?

here is the page of code including the JS and email form:

Code:
[B]<html>[/B]
[B]<head>[/B]

[B][B]<script type="text/javascript" language="JavaScript">[/B][/B]


//validating email address
    re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

    [I]function[/I] submitit(myform) {

    [I]if[/I] (re.test(myform.emailaddr.value)) {
        [I]return[/I] [I]true[/I]
}
    [I]alert[/I]("invalid email address")
    myform.emailaddr.focus( )
    myform.emailaddr.select( )
    [I]return[/I] [I]false[/I]
}

    [I]function[/I] validform(emailaddrform) {
    [I]if[/I] (emailaddrform.emailaddr1.value == "") {
    [I]alert[/I]("You must enter an email address")
    emailaddrform.emailaddr1.focus( )
    [I]return[/I] [I]false[/I]

}
    [I]if[/I] (emailform.emailaddr1.value ! = emailform.emailaddr2.value) {
    [I]alert[/I]("Entered email addresses did not match")
    emailform.emailaddr1.focus( )
    emailform.emailaddr1.select( )
    [I]return[/I] [I]false[/I]
    }
    [I]return[/I] [I]true[/I]
}

[B][B]</script>[/B][/B]
[B]</head>[/B]
[B]<body>[/B]
[B]<table border="1" width="100%">[/B]
[B]<tr>[/B]
[B]<td width="10%">[/B]
[B]<map name="homeleft" id="homeleft" align="left">[/B]
[B]<area shape="rect" coords="10, 10, 212, 219" href="index.html"/>[/B]
[B]<area shape="rect" coords="66, 253, 168, 303" href="realestatepost.html"/>[/B]
[B]<area shape="rect" coords="66, 342, 168, 391" href="graphics.html"/>[/B]
[B]</map>[/B]

[B]<img src="http://i95.photobucket.com/albums/l136/surreal5335/web%20builder/homeleft.png"  usemap="#homeleft" id="homeleft" hspace="10" vspace="10" align="center">[/B][B]<br>[/B]

[B]</td>[/B]
[B]<td width="80%">[/B]
<!--home content--!>

[B]<img src="http://i95.photobucket.com/albums/l136/surreal5335/web%20builder/portfolioheader.png" hspace="10" vspace="10" align="center">[/B][B]<br/>[/B][B]<br>[/B]
[B][U]<form method="post" name="emailform" action="emailform.php">[/U][/B]
[B]<p class="legend">[/B]Contact via email[B]</p>[/B]
[B]<fieldset id="conact">[/B]
[B][U]<[I]label[/I]>[/U][/B]Name: [B][U]</[I]label[/I]>[/U][/B][B][U]<input type="text" name="name" size="30"/>[/U][/B][B]<br/>[/B]
[B]<br>[/B]
[B][U]<[I]label[/I]>[/U][/B]Email:  [B][U]</[I]label[/I]>[/U][/B][B][U]<input type="text" name="emailaddr1" size="30"/>[/U][/B][B]<br/>[/B]
[B]<br>[/B]
[B][U]<[I]label[/I]>[/U][/B]Email:  [B][U]</[I]label[/I]>[/U][/B][B][U]<input type="text" name="emailaddr2" size="30"/>[/U][/B][B]<br/>[/B]
[B]<br>[/B]
[B][U]<[I]label[/I]>[/U][/B]Phone: [B][U]</[I]label[/I]>[/U][/B][B][U]<input type="text" name="phone" size="30"/>[/U][/B][B]<br/>[/B]
[B]<br>[/B]
[B][U]<[I]label[/I]>[/U][/B]Comments: [B][U]</[I]label[/I]>[/U][/B][B]<br>[/B][B][U]<textarea name="comments" rows="10" cols="30">[/U][/B]Please give me a brief description of the work you need done[B][U]</textarea>[/U][/B][B]<br/>[/B]
[B]<br>[/B]
[B][U]<input type="submit" name="submit">[/U][/B][B]<a href="thankyou.html">[/B][B]</a>[/B][B][U]</button>[/U][/B][B]<br/>[/B]

[B]</td>[/B]
[B]<td width="10%">[/B]

[B]<map name="homeright" id="homeright" align="left">[/B]
[B]<area shape="rect" coords="37, 530, 191, 683" href="contact.html"/>[/B]
[B]</map>[/B]

[B]<img src="http://i95.photobucket.com/albums/l136/surreal5335/web%20builder/homeright.png"  usemap="#homeright" id="homeright" hspace="10" vspace="10" align="center">[/B][B]<br>[/B]
[B]</td>[/B]
[B]</tr>[/B]
[B]</body>[/B]
[B]</table>[/B]
[B]</html>[/B]

Thanks a lot for your help
 

bonzo meier

Member
Messages
47
Reaction score
0
Points
6
hi,

you should add an onClick-action to the button field:
change your code
<input type="submit" name="submit"><a href="thankyou.html"></a></button><br/>

to:
<input type="submit" name="submit" onClick="validform('emailform');"><a href="thankyou.html"></a></button><br/>

or something like that.

success!
bonzo
 

VPmase

New Member
Messages
914
Reaction score
0
Points
0
"myform.emailaddr.value" this and others like it should have "document." infront of it.
"document.myform.emailaddr.value";

Also
<input type="submit" name="submit"> should be
<input type="button" name="submit" value="Send Email" onclick="submitit();" />
Then on the emailform.php is where you include the thank you page. Otherwise if you click that link it will take you to the thankyou page without sending the email.
 

lszanto

New Member
Messages
23
Reaction score
0
Points
0
I'm sure you proberly know this but i'm just checking, make sure you have other validation on your website and don't rely on javascript. You can easily get around it and/or simply disable it.
 
Top