RomeosKlassicDJ
07-15-2011, 04:10 PM
Let's start by saying that I stink at javascript. I've taken multiple different tutorials, some more than once, and I still can't get it. So, when I need a code, I search for it, and try different ones until I find something that works.
I've been looking for a code for email validation for quite a long time, and I still can't find something that works with my code for validating the other parts of my contact form. I can get it to check for the presence of text, but not for the presence of an @ sign and period. I would like for someone to please help me figure this out.
Right now I have the following code:
Javascript
<!--
function validate_form ( )
{
valid = true;
if ( document.contact.firstnamecontact.value == "" )
{
alert ( "Please fill in the 'First Name' box." );
valid = false;
}
if ( document.contact.lastnamecontact.value == "" )
{
alert ( "Please fill in the 'Last Name' box." );
valid = false;
}
if ( document.contact.emailcontact.value == "" )
{
alert ( "Please fill in a valid email address." );
valid = false;
}
if ( document.contact.subjectcontact.value == "" )
{
alert ("Please fill in the 'Subject' box." );
valid = false;
}
if ( ( document.contact.topic[0].checked == false )
&& ( document.contact.topic[1].checked == false )
&& ( document.contact.topic[2].checked == false ) )
{
alert ( "Please choose your Topic of Inquiry" );
valid = false;
}
if ( document.contact.messagecontact.value == "" )
{
alert ( "Please specify a question/comment." );
valid = false;
}
return valid;
}
//-->
HTML
<form name="contact" method="post" action="contactcompletion.php3" onsubmit="return validate_form ( );">
<table>
<tr>
<td><b>First Name: </td><td><input type="text" name="firstnamecontact"/></td>
</tr>
<tr>
<td><b>Last Name: </b></td><td><input type="text" name="lastnamecontact"/></td>
</tr>
<tr>
<td><b>Email: </b></td><td><input type="text" name="emailcontact"/></td>
</tr>
<tr>
<td><b>Subject: </b></td><td><input type="text" name="subjectcontact"/></td>
</tr>
</table>
<br />
<br />
<h4>Topic of Inquiry (Choose One):</h4>
<table>
<tr>
<td><input type="radio" name="topic" value="questionscontact" /><b> Questions</b></td>
<td><input type="radio" name="topic" value="commentscontact" /><b> Comments</b></td>
<td><input type="radio" name="topic" value="othercontact" /><b> Other</b></td>
</tr>
</table>
<br />
<br />
<h4>Enter Your Questions or Comments:</h4>
<br />
<textarea name="messagecontact" rows="10" cols="70"></textarea>
<br />
<br />
<p><input type="submit" name="send" value="Send" /></p>
Thanks a bunch in advance for helping me!!
I've been looking for a code for email validation for quite a long time, and I still can't find something that works with my code for validating the other parts of my contact form. I can get it to check for the presence of text, but not for the presence of an @ sign and period. I would like for someone to please help me figure this out.
Right now I have the following code:
Javascript
<!--
function validate_form ( )
{
valid = true;
if ( document.contact.firstnamecontact.value == "" )
{
alert ( "Please fill in the 'First Name' box." );
valid = false;
}
if ( document.contact.lastnamecontact.value == "" )
{
alert ( "Please fill in the 'Last Name' box." );
valid = false;
}
if ( document.contact.emailcontact.value == "" )
{
alert ( "Please fill in a valid email address." );
valid = false;
}
if ( document.contact.subjectcontact.value == "" )
{
alert ("Please fill in the 'Subject' box." );
valid = false;
}
if ( ( document.contact.topic[0].checked == false )
&& ( document.contact.topic[1].checked == false )
&& ( document.contact.topic[2].checked == false ) )
{
alert ( "Please choose your Topic of Inquiry" );
valid = false;
}
if ( document.contact.messagecontact.value == "" )
{
alert ( "Please specify a question/comment." );
valid = false;
}
return valid;
}
//-->
HTML
<form name="contact" method="post" action="contactcompletion.php3" onsubmit="return validate_form ( );">
<table>
<tr>
<td><b>First Name: </td><td><input type="text" name="firstnamecontact"/></td>
</tr>
<tr>
<td><b>Last Name: </b></td><td><input type="text" name="lastnamecontact"/></td>
</tr>
<tr>
<td><b>Email: </b></td><td><input type="text" name="emailcontact"/></td>
</tr>
<tr>
<td><b>Subject: </b></td><td><input type="text" name="subjectcontact"/></td>
</tr>
</table>
<br />
<br />
<h4>Topic of Inquiry (Choose One):</h4>
<table>
<tr>
<td><input type="radio" name="topic" value="questionscontact" /><b> Questions</b></td>
<td><input type="radio" name="topic" value="commentscontact" /><b> Comments</b></td>
<td><input type="radio" name="topic" value="othercontact" /><b> Other</b></td>
</tr>
</table>
<br />
<br />
<h4>Enter Your Questions or Comments:</h4>
<br />
<textarea name="messagecontact" rows="10" cols="70"></textarea>
<br />
<br />
<p><input type="submit" name="send" value="Send" /></p>
Thanks a bunch in advance for helping me!!