PDA

View Full Version : Can some1 help me with a bit of java script please???


dj_lloyde
05-10-2004, 05:03 AM
Basically Ive made a form where all the fields need to be filled in. if they aint then a message will come up saying so and so field isnt complete.
My prob is ive got 2 put in a password part that checks to see if both passwords are the same,
So when someone clicks submit i need it to check all fields are filled out and that both paswwords are the same.
Thanks in advance for any help.

here is my code

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function checkFields() {
missinginfo = "";
if (document.form.sid.value == "") {
missinginfo += "\n - SID Number";
}
if (document.form.firstname.value == "") {
missinginfo += "\n - First Name";
}
if (document.form.surname.value == "") {
missinginfo += "\n - Surname Name";
}
if (missinginfo != "") {
missinginfo =
"Error the following field need to be completed:\n" +
missinginfo +
"\nPlease re-enter your details and submit again!";
alert(missinginfo);
return false;
}
else return true;
}
</script>
<SCRIPT LANGUAGE="JavaScript">

function checkPw(form) {
pw1 = form.pw1.value;
pw2 = form.pw2.value;
if (pw1 != pw2) {
alert ("\nYou did not enter the same new password twice. Please re-enter your password.")
return false;
}
else return true;
}
</script>
<title>Form Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#0000FF" text="#FFFF00">
<form name=form onSubmit="return checkFields();">
<input type=hidden name=to value='you @ your domain . web'>
<input type=hidden name=subject value="Freedback">
<pre>
SID <input type=text name="sid" size=30>
First Name: <input type=text name="firstname" size=30>
Surname: <input type=text name="surname" size=30>
</pre>


<p>Password:
<input type=password name=pw1 size=10>
</p>
<p>Re-enter:
<input type=password name=pw2 size=10>
</p>
<pre>

<input type=submit name="submit" value="Submit Form!">&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="Reset" value="Reset Form!">
</pre></form>
</body>
</html>

This is the password code im trying to put in


<SCRIPT LANGUAGE="JavaScript">

function checkPw(form) {
pw1 = form.pw1.value;
pw2 = form.pw2.value;
if (pw1 != pw2) {
alert ("\nYou did not enter the same new password twice. Please re-enter your password.")
return false;
}
else return true;
}
// End -->
</script>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<form onSubmit="return checkPw(this)">
<center>
<table border=0>
<tr>
<td>Password:</td><td><input type=text name=pw1 size=10></td>
</tr>
<tr>
<td>Re-enter:</td><td><input type=text name=pw2 size=10></td>
</tr>
<tr>
<td colspan=2 align=center><input type=submit value="Submit!"></td>
</tr>
</table>
</form>

dj_lloyde
05-12-2004, 05:38 PM
any1 please?

celtic_druid
05-12-2004, 06:05 PM
<form name=form onSubmit="return checkFields() && checkPw(form);">

dj_lloyde
05-13-2004, 05:45 AM
cheers m8