Hello, I want to validate this form and display error right next to the input field.
<div id="regForm">
<form action="register.php" method="POST" onsubmit="return validate(this);"id=registration" name="registration"><p>
Username: <input type="text" name="username" id="username_reg" /><br />
Password: <input type="password" name="password" id="password_reg" /><br />
Repeat password: <input type="password" name="repeatPassword" id="repeat_reg" /><br />
Email: <input type="text" name="email" id="email_reg" /><br />
<input type="submit" name="submit" value="Register" /></p>
</form>
</div>
if(elemValue[i] == "" || elemValue[i] == null){
error[error.length] = "This field must be filled";
var msg = document.createElement('p');
var txt = document.createTextNode(error[error.length - 1]);
msg.appendChild(txt);
How can I add this text to appear right after the input field ??
It should be something like the code below.
<form>
<p><input type="text" name="formName" id="formId" />ERROR: This field must be filled</p>
</form>