ここに私のコードplzが私を助けてくれます
$(document).ready(function() {
// validate signup form on keyup and submit
var validator = $("#signupform").validate({
rules: {
username: {
required: true,
minlength: 6,
maxlength: 12,
remote:"users.php"
},
password: {
required: true,
minlength: 6,
maxlength: 12
},
email:
{
required: true,
minlength: 15,
maxlength: 50,
remote:"email.php"
}
},
messages: {
username: {
minlength: "username is 6 to 12 characters",
maxlength: "username is 6 to 12 characters",
required: " username should be required",
remote: " username should be already exists"
},
password: {
minlength: "password is 6 to 15 characters",
maxlength: "password is 6 to 12 characters 12",
required: " password should be required",
},
email: {
minlength: "Email is 15 to 50 characters",
maxlength: "Email is 15 to 50 characters",
required: " Email should be required",
remote: " Email should be already exists"
}
},
// specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function()
{
alert("submitted!---------");
$("#signupform").submit();
},
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element)
{
error.prependTo( element.parent().next() );
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("checked");
}
});
// propose username by combining first- and lastname
$("#username").focus(function() {
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
if(firstname && lastname && !this.value) {
this.value = firstname + "." + lastname;
}
});
});
そしてフォームは
<form id="signupform" name="signupform" method="post" action="register.php" style="padding-top:70px;" >
<table align="center" style="height:200px;">
<tr>
<td class="field"><span style="width:150px;color:black;font-weight:bold;">Username:</span> <input id="username" name="username" style="height:25px;width:155px;" onKeyPress='return alphanumericPass(event, false)' type="text" value="Username (6 to 12 chars)" maxlength="12" onfocus="if(this.value=='Username (6 to 12 chars)')this.value=''" onblur="if(this.value=='')this.value='Username (6 to 12 chars)'" placeholder="Username" /></td>
<td class=""></td>
</tr>
<tr>
<td class="field"><span style="width:150px;color:black;font-weight:bold;">Password:</span> <input id="password" name="password" style="height:25px;width:155px;" onKeyPress='return alphanumericPass(event, false)' type="password" maxlength="12" placeholder="Password" /></td>
<td class=""></td>
</tr>
<tr>
<td class="field" align="left"><span style="width:150px;color:black;font-weight:bold;">Email:</span> <input id="email" name="email" style="height:25px;width:155px;" type="text" value="Email Address" onfocus="if(this.value=='Email Address')this.value=''" onblur="if(this.value=='')this.value='Email Address'"/></td>
<td class=""></td>
</tr>
<tr>
<td style="width:200px;"><div><font size="1" color="#000000">By clicking 'Register Now' you are agreeing to our <a href="terms_con.php" target="_blank" style="color:red" > Terms and Conditions </a></font></div> </td>
</tr>
<tr align="">
<td class="field" align="" colspan="2" style="padding-left:70px;">
<input align="left" value="" id="signupsubmit" name="signup" type="image" src="images/nsignup.png" />
</td>
</tr>
</table>
</form>