When submitting a form, I have implemented a check to see if the value already exists in the database. The AJAX post is returning the correct result, but there is an issue when trying to display an alert for the wrong result. Even though the JavaScript alert and focus work as expected, the form still submits afterwards.
Here is the submit button:
<input type="submit" name="kaydet" class="btn btn-success form-control" onClick="return kaynak_kontrol()" value="Kaydet">
Below is the AJAX code:
<script type="text/javascript>
function kaynak_kontrol(){
Form=document.forms['depo_kayit'];
var depo_sube_no = document.getElementById('depo_sube_no').value;
var depo_firma_no = document.getElementById('depo_firma_no').value;
var depo_kodu = document.getElementById('depo_kodu').value;
var dataString ="depo_sube_no="+depo_sube_no+"&depo_firma_no="+depo_firma_no+"&depo_kodu="+depo_kodu;
$.ajax({
type: "POST",
url: "depo_kodu_kontrol.php",
data: dataString,
success: function(result){
if(result != 0){
alert("Aynı şubede aynı isimde iki depo olamaz!");
document.getElementById('depo_kodu').focus();
return false;
} else {
return true;
Form.submit();
}
}
});
}
</script>
Could someone assist me with understanding why the 'return false' statement is not preventing the form from being submitted?