I\'m trying to validate a form using JavaScript but i\'m a bit stuck on displaying a message next to the field to say that \"This field is required\". How do I go about doing th
Your way of validation form fields is absolutely terrible, a lot of unneded and bloated code which is not optimized at all.
I will strongly reccomend you use some sort of readyly available FormValidation script or have a look at this jQuery plugin
Using jQuery your code can look like this (plus you also get the messages to appear next to field):
$("#signupForm").validate({
rules: {
firstname: "required",
lastname: "required",
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
},
email: {
required: true,
email: true
}
}
})