I trie to write a simple validation function. For some response I can’t get the function to return the boolean. For now I got no response from clicking submit at all.
$.fn.ValidateSelect = function() {
//function ValidateSelect() { (this works)
var selected = $('select[name="my-item-size"]').val();
var validate = false;
if (selected != 'none') {
validate = true;
} else {
validate = false;
}
if (validate == true) {
return true
} else {
return false
}
};
//submit
$('.add_item_button').click(function() {
if (ValidateSelect() == true) {
$('#item_submit').submit();
} else {
alert('Please select your brand first.')
}
});
You don’t need a jQuery extension but a javascript function.