javascript form validation

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

01-May-07 00:06
Im not sure if I am asking this question in the right place, however, I am getting desperate. I am taking a web dev. class and having extreme difficulty with code to validate a simple form. I am an accountant with little or no experience in this area. I designed the form in dreamweaver and need to validate a few fields. I copied the code I found online and it doesn't work - I can't get past the first field!!! Im sure for you Web Dev. this is aobut as basic as it gets... but not for me.
If there is anyone out there who could peak at my work and tell me what I did wrong I would be extremely grateful to say the least!!!
Jill
01-May-07 01:11
We'll see if we can help! Can you post the URL of your form and JavaScript so we can take a look?

You can also try viewing your JavaScript error messages (e.g. in Firefox choose Tools > Error Console). This will help you pinpoint the exact problem.

Matt
ELATED : )

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
01-May-07 01:26
Thanks for responding!!!! don't laugh at the code of this form...its my first...my assignment is to make sure first name, last name and password are not blank. And a valid email address. I can't get past the first name

C:\Documents and Settings\JGemma.NSMITHFIELDRI\Desktop\MSIS641WebDev\GemmaLab07.htm

Does that file open?

if you need my email it is dolcevita_2001@hotmail.com

Jill
01-May-07 01:31
You'll need to upload that .htm file to a website somewhere so we can see it. Or you could just post the source here? (Click Post a Reply, then copy and paste the source code into the message box.)

Matt
ELATED : )

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
01-May-07 01:35
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
<!--
function validate_form ( )
{
valid = true;

if ( document.studentinfo.firstname.value == "" )
{
alert ( "Please fill in the 'First Name' box." );
valid = false;
}
return valid;
}
//-->
</script>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>GemmaLab07</title>

<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
.style1 {
font-family: "Times New Roman", Times, serif;
font-size: 36px;
}
body,td,th {
font-weight: bold;
}
-->
</style></head>

<body>

<div align="center">
<p class="style1">MSIS643 Student Information Form</p>
<form action="http://www.jjswebdev.com/echoform.php" method="post" enctype="text/plain" name="studentinfo" id="studentinfo">
<table width="113%" border="4" align="left" cellpadding="3" cellspacing="0" bordercolor="#999999" bgcolor="#FFCC99">
<tr>
<td width="48%" height="58">
<div align="left">
<label>First name:
<input name="firstname" type="text" id="firstname" size="30">
</label>
</div></td>
<td width="52%"><div align="left">
<label> Bryant Student ID#
<input name="id" type="text" id="id" size="15" maxlength="9">
</label>
</div></td>
</tr>
<tr>
<td height="56"><div align="left">
<label> Last name:
<input name="lastname" type="text" id="lastname" size="30">
</label>
</div></td>
<td><div align="left">
<label> Email:
<input name="email" type="text" id="email" size="30">
</label>
</div></td>
</tr>
<tr>
<td height="57"><p align="left">Number of MSIS Courses Completed:
<select name="select">
<option value="Select #">Select #</option>
<option value="1-3">1-3</option>
<option value="4-6">4-6</option>
<option value="7-9">7-9</option>
<option value="more than 9">more than 9</option>
</select>
</p>
</td>
<td><div align="left">
<label>Select Password (6 chars max):
<input name="password" type="password" id="password" maxlength="6">
</label>
</div></td>
</tr>
<tr>
<td height="96" valign="top"><div align="left"><br>
Grade for course Prerequisite MSIS641: <br>
<br>
<table width="60%" border="1" align="center" cellpadding="2" cellspacing="10" bgcolor="#009999">
<tr>
<td width="53%" height="50"><p>
<label>
<input type="radio" name="Grade" value="A / AB">
A / AB</label>
<br>
<label>
<input type="radio" name="Grade" value="B / BC">
B / BC</label>
<br>
</p></td>
<td width="47%"><p>
<label>
<input type="radio" name="Grade" value="C">
C</label>
<br>
<label>
<input type="radio" name="Grade" value="F">
F</label>
<br>
</p></td>
</tr>
</table>
<br>
</div></td>
<td valign="top"><div align="left"><br>
Computer/OS experience: (check all that apply)<br>
<br>
<label> <input name="experience" type="checkbox" id="experience" value="Windows">
PC/Windows</label>
<br>
<label> <input name="experience" type="checkbox" id="experience" value="Linux">
PC/Linux</label>
<br>
<label> <input name="experience" type="checkbox" id="experience" value="MAC">
Mac/MacOS</label>
<br>
<label> <input name="experience" type="checkbox" id="experience" value="Sun">
Sun/Solaris</label>
<br>
<br>
</div></td>
</tr>
<tr valign="top">
<td height="104" colspan="2"><div align="left"><br>
Tell me a little about your interests and hobbies:
<label>

<br>
<br>
<textarea name="interests" cols="120" rows="5" id="interests"></textarea>
<br>
</label></div></td>
</tr>
<tr bgcolor="#CCCCCC">
<td>
<div align="right">
<label>
<input type="submit" name="Submit" value="Submit Form">
</label>
</div></td>
<td>
<div align="left">
<input name="Reset" type="reset" value="Reset Form">
</div></td>
</tr>
</table>
</form>
<p> </p>
</div>
</body>
</html>
01-May-07 02:25
You missed the onsubmit event handler in your form tag. Try this:

<form action="http://www.jjswebdev.com/echoform.php" method="post" enctype="text/plain" name="studentinfo" id="studentinfo" onsubmit="return validate_form();">

Matt
ELATED : )

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
01-May-07 02:34
Thanks Matt...i will try this!!!
Jill
01-May-07 02:42
No problem Jill. Let us know how you get on!

Matt
ELATED : )

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/
01-May-07 02:43
It worked Matt!! you made my night Thanks
Jill
01-May-07 02:56
Great stuff - I'm glad you got it working
Matt

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/

 
New posts
Old posts

Follow Elated