Is There A Way To Prevent A Form From Being Submitted If It Is Not Auto Completed?
Solution 1:
Have the form loaded with the button as disabled. As you are filling up the form, you have a running tally of flags (class=validation) to notify when the form is ready, then you can enable the button.
There is no sense in having a workable button that will attempt to call the server if you already know that it should fail if not all the information is ready.
The example in the bottom will work if you fill up all three boxes with text. You can signify controls by having each textbox with a class append text "required" in red font using the appendTo() in jquery.
As long as there is a class validation on the html element, it will be required, so as we are entering data, it will remove those validation classes:
<html>
<head>
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input[name^='test']").blur(function(){
if ($(this).val() != "" && $(this).hasClass("validation")){
$(this).removeClass("validation");
}
var check = $(".validation"); //checks to see if there is any more validation
if (check.length == 0){
$("#nowSubmit").prop("disabled", false);
} else {
$("#nowSubmit").prop("disabled", true);
}
});
});
</script>
</head>
<body>
<form>
<input id="control1" name="test" type="textbox" class="validation" />
<input id="control2" name="test" type="textbox" class="validation" />
<input id="control3" name="test" type="textbox" class="validation" />
<input id="nowSubmit" type="submit" value="Click Here" disabled="true"/>
</form>
</body>
</html>
working example here: http://jsfiddle.net/hSatZ/
Solution 2:
You can use ajax request put on "onchange" event on autocomplete fields which would check if specific value is in db and will notify user about error if needed without submitting the form
Post a Comment for "Is There A Way To Prevent A Form From Being Submitted If It Is Not Auto Completed?"