The custom function formdvalidate should run after else but it doesn’t. How can I trigger it to run?
What I like to accomplish here is to check the text-fields of a form. If there are less then 3 characters its show the user some text. If the input is more then 3 it submits the form.
–I was thinking to wrong way, this works better.
$('#submit').click(formdvalidate);
The function
function formdvalidate(){
$(".form-sel").each(function(){
var n = $(this).closest('.contain-form').find('.custom:first').val().length;
if ($('option:selected', this).val() === 'custom' && n < 3) {
$(this).closest('.contain-form').find('.alert-short:first').show();
}else{
$('#poll').submit();
}
});
}
.click()takes a jQuery event object as its first param–you named that param the same as your functionformdvalidate === truewill never evaluate to true asformdvalidateis a function in the global scope, and a jQuery event object in theclick()scope as per item 1formdvalidatefunction, your return is inside of the.each()function, soformdvalidatenever actually returns anything.I’m not sure what you’re really after or what your page looks like, but based on your comment to Slava Yanson, my best guess for you is below (although there are still things I am unsure of…)