Just after a check to make sure one hidden field is not empty.
if($('#cal_startdate').val('')) {
alert('Please select a start date') }
else { form.submit }
That isn't quite right. I'd rather it was an onsubmit action.
Any ideas,
Marvellous
E开发者_开发技巧DIT
What about this:
$('#formId').submit(function(){
if($('#cal_startdate').val() == ""){
alert('Please select a start date');
return false; // To avoid the submit (error)
}
});
You'll want to attach the validation to the submit()
event handler. If data is valid, return true - else, return false.
$('form').submit(function(){
if ($('#cal_startdate').val().length==0){
alert('Please Enter Start Date');
return(false);
}
return(true);
});
$("form").submit(function(){
if($("#cal_startdate").val() === ""){
alert("Please select a start date");
return false;
})
})
Beware, here you are using val()
as a setter. Effectively, calling <selection>.val('')
will set your input to something empty. What you want to do is the following:
if($('#cal_startdate').val() === '')
alert('Please select a start date');
else
form.submit();
That should work now
精彩评论