I have a page which has 2 text areas and wanted to validate each text area if the characters being typed is more than max length upon clicking submit button. Problem with the code below when clicking submit it can only detect if textarea1 is more than max length but not the other textarea. What I wanted to do is it can determine which textarea is exceeding maxlength so users can correct it. Thanks in advance.
<html>
<head>
<script>
function testing()
{
var txtlength=document.getElementById("txt1").value.length;
if(txtlength>50)
{
alert("Max1 length reached ");
return false;
}
else
{
return true;
}
var txtlength1=document.getElementById("txt2").value.length;
if(txtlength1>50)
{
alert("Max2 length reached ");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="test1.html" method="post" onsubmit="return testing();">
<textarea id="txt1"></textarea>
<textarea id="txt2"></textarea>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
returnexits the function. The second block of code is never reached.