I am making jQuery confirmation and I am having a problem. So far, I have the following code:
$('form').submit(function () {
'use strict';
if (!Modernizr.input.required) {
$(this).find('input[required]').each(function () {
if ($(this).val() === '') {
var requiredFieldWarning = document.createElement('span');
requiredFieldWarning.text = 'This field is required.';
}
});
}
});
I am trying to โattachโ or display spannext to any input of a submitted form that is not validated, but I donโt know how to do it. I want to do this unobtrusively, so I am creating the specified spaninside JavaScript.
Also, how can I prevent a form from being submitted if any of the fields in the submitted form is not confirmed?
source
share