Jump to content

<input required>


knutsford
 Share

Recommended Posts

For that you'll need Javascript.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>title</title>
<script>
window.onerror = function(a,b,c){
alert('Javascript Error: '+a+'\nFile: '+b+'\nLine: '+c);
return true;
}
</script>
<script>
'use strict';

function validateForm(evt){
var txt = document.getElementById('txt1').value.trim();
if (txt.length < 8){
evt.preventDefault();
alert('Submission Aborted\nText is only ' + txt.length + ' characters');
}
}

window.onload = function(){
document.getElementById('form1').onsubmit = validateForm;
}

</script>
</head>

<body>

<form id="form1">
<input type="text" name="txt1" id="txt1"/>
<input type="submit" value="Submit"/>
</form>

</body>    
</html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...