<script type="text/javascript">
$().ready(function() {
// validate signup form on keyup and submit
$("#signupForm").validate({
ignore:":hidden",
rules: {
firstname: "required",
lastname: "required",
username: {
required: true,
minlength: 2
}
},
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
}
});
});
</script>
<form action="" method="post">
<select>
<option value="volvo">Option one</option>
<option value="saab">Option two</option>
</select>
<!-- BEGIN OPTION ONE -->
<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="lastname">Lastname</label>
<input id="lastname" name="lastname" />
</p>
<!-- END OPTION ONE -->
<!-- BEGIN OPTION TWO -->
<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="lastname">Lastname</label>
<input id="lastname" name="lastname" />
</p>
<!-- END OPTION TWO -->
</form>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// validate signup form on keyup and submit
$("#signupForm").validate({
ignore:":hidden",
rules: {
firstname: "required",
lastname: "required",
username: {
required: true,
minlength: 2
}
},
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
}
});
$("select").change(function() {
$(".section").hide();
var indexOfToShow = $("select>option:selected").index("select>option");
$(".section:eq(" + indexOfToShow + ")").fadeIn("slow");
});
});
</script>
</head>
<body>
<form id="signupForm" action="" method="post">
<select>
<option value="volvo">Option one</option>
<option value="saab">Option two</option>
</select>
<!-- BEGIN OPTION ONE -->
<div class="section">
<p>
<label for="firstname">Firstname </label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="lastname">Lastname</label>
<input id="lastname" name="lastname" />
</p>
</div>
<!-- END OPTION ONE -->
<!-- BEGIN OPTION TWO -->
<div class="section">
<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="lastname">Lastname</label>
<input id="lastname" name="lastname" />
</p>
</div>
<!-- END OPTION TWO -->
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// validate signup form on keyup and submit
$("#signupForm").validate({
ignore:":hidden",
rules: {
firstname: "required",
lastname: "required",
username: {
required: true,
minlength: 2
}
},
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
}
});
$("select").change(function() {
$(".section").hide();
var indexOfToShow = $("select>option:selected").index("select>option");
$(".section:eq(" + indexOfToShow + ")").fadeIn("slow");
}).change();
});
</script>
</head>
<body>
<form id="signupForm" action="http://www.experts-exchange.com" method="post">
<select>
<option value="volvo">Option one</option>
<option value="saab">Option two</option>
</select><input type="submit" value="Submit" />
<!-- BEGIN OPTION ONE -->
<div class="section">
<p>
<label for="firstname">Firstname </label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="lastname">Lastname</label>
<input id="lastname" name="lastname" />
</p>
</div>
<!-- END OPTION ONE -->
<!-- BEGIN OPTION TWO -->
<div class="section">
<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" />
</p>
<p>
<label for="lastname">Lastname</label>
<input id="lastname" name="lastname" />
</p>
</div>
<!-- END OPTION TWO -->
</form>
</body>
</html>
Open in new window
Test page :
Open in new window