I want to stop my form from submitting and taking an action on going to another php file if the form has no value from at least one of its variables.
<form id="advform" class="" action="advancedsearching.php" method="GET" onsubmit = "return validate()" autocomplete="off" >
<div class="modal-header align-items-center justify-content-center py-2 ">
<h4 class="modal-title">Advanced Search</h4>
</div>
<div class="modal-body ">
<div class="form-group">
<label>Title:</label>
<input type="text" name="title" class="form-control" autocomplete="off" autocomplete="false" >
</div>
<div class="form-group">
<label>Author:</label>
<input type="text" name="author" class="form-control" autocomplete="off" autocomplete="false" >
</div>
<div class="form-group">
<label>ISBN:</label>
<input type="text" name="isbn" class="form-control" autocomplete="off" autocomplete="false" >
</div>
<div class="form-group">
<label>Publisher:</label>
<input type="text" name="publisher" class="form-control" autocomplete="off" autocomplete="false" >
</div>
<div class="form-group">
<label>Keyword:</label>
<input type="text" name="keyword" class="form-control" autocomplete="off" autocomplete="false" >
</div>
</div>
<div class="modal-footer justify-content-center ">
<input type="submit" class="btn btn-dark" value="Search" style="width:100%;border:1px solid black;">
</div>
</form>
tried adding
<script>
function validate() {
var x;
x = document.getElementById("advform").value;
if (x == "") {
alert("Please Enter a Value");
return false;
};
}
</script>
but it is still submitting
requiredattribute? Also, what have you tried to check why your approach is not working as expected?