I have this javascript function in my page.
$(document).ready(function(){
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="InfiStallStock"){
$(".e-stock-saldo-box").hide();
$(".InfiStall ul li .infistallLocation").attr('required');
$(".Delivery ul input:radio").removeAttr('required');
$(".Delivery ul input:text").removeAttr('required');
$(".InfiStall").show();
}
if($(this).attr("value")=="DeliveryStock"){
$(".e-stock-saldo-box").hide();
$(".InfiStall ul li .infistallLocation").removeAttr('required');
$(".Delivery ul li input:radio").attr('required');
$(".Delivery ul input:text").attr('required');
$(".Delivery").show();
}
});
});
function enableList(element) {
var select = document.getElementById("select"+element.id.substring(element.id.length-9));
enableSubmit();
showUp();
if(element.checked === true){
select.disabled = false;
checkSelect(select);
}else{
select.disabled = true;
select.selectedIndex = 0;
}
}
function checkSelect(element){
if(!validate_select(element)){
element.setCustomValidity("Pilih Jumlah Estock");
}else{
element.setCustomValidity("");
}
}
This javascript functioned to check which option select by user. If user choose one option, then another option which has required input will be ignored/removed, and vice versa.
The javascript is working great in validate the form if I submit the form directly with form action like <form action="submit.php"/>
.
However, when I change the way to submit it which is now with ajax, the validation is ignored.
Here is the ajax script to submit the form:
$('#btn_submit').on('click', function(e) {
e.preventDefault();
var esquantity = $('.row_selected select').map(function() { return $(this).val(); }).get().join('|');
var size = $('.row_selected td.size span').map(function() { return $(this).text(); }).get().join('|');
$.ajax(
{
type: "POST",
url: "../ajax.php",
data: 'esquantity='+esquantity+ '&size='+ size,
cache: false,
success:function(html)
{
alert("Succes " + html);
}
});
Can anybody help me how to solve this please, so that this form will have some validations even though I submit it with ajax. Thanks!