Here's what I've tried so far.
<head>
<script>
function myFunction() {
var a = document.forms["login"]["uname"].value;
var b = document.forms["login"]["pwd"].value;
if (a == "" || b == "") {
error = "All fields must be entered.";
document.getElementById("errorid").innerHTML = error;
}
}
</script>
</head>
<body>
<form name="login" action="">
<b>Enter username:</b>
<input type="text" name="uname" />
<br />
<b>Enter password:</b>
<input type="password" name="pwd" />
<br />
<p id="errorid"></p>
<input onclick="myFunction()" type="submit" />
</form>
</body>
</html>
But it's not displaying the error message in p tag with ID = errorid Have I written wrong code? If yes then how can this be fixed?