Untitled
unknown
plain_text
2 years ago
2.6 kB
11
Indexable
function live(selector, event, callback, context) {
/****Helper Functions****/
// helper for enabling IE 8 event bindings
function addEvent(el, type, handler) {
if (el.attachEvent) el.attachEvent("on" + type, handler);
else el.addEventListener(type, handler);
}
// matches polyfill
this.Element &&
(function(ElementPrototype) {
ElementPrototype.matches =
ElementPrototype.matches ||
ElementPrototype.matchesSelector ||
ElementPrototype.webkitMatchesSelector ||
ElementPrototype.msMatchesSelector ||
function(selector) {
var node = this,
nodes = (node.parentNode || node.document).querySelectorAll(selector),
i = -1;
while (nodes[++i] && nodes[i] != node);
return !!nodes[i];
};
})(Element.prototype);
// live binding helper using matchesSelector
function live(selector, event, callback, context) {
addEvent(context || document, event, function(e) {
var found,
el = e.target || e.srcElement;
while (el && el.matches && el !== context && !(found = el.matches(selector))) el = el.parentElement;
if (el && found) callback.call(el, e);
});
}
live(selector, event, callback, context);
}
const validateEmail = (email) => {
return email.match(
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
};
live('html body [id^="gform_submit_button"]', 'click', function() {
const fNm = document.querySelector('html body [id^="gform"][action="/contact-us/"] .name_first input');
const lNm = document.querySelector('html body [id^="gform"][action="/contact-us/"] .name_last input');
const cmp = document.querySelector('html body [id^="gform"][action="/contact-us/"] input#input_5_7');
const eml = document.querySelector('html body [id^="gform"][action="/contact-us/"] input#input_5_8');
if((fNm && fNm.value.trim() !== "") && (lNm && lNm.value.trim() !== "") && (cmp && cmp.value.trim() !== "") && (eml && validateEmail(eml.value))){
console.log('Form submitted!');
} else {
console.log('Form not submitted!');
}
});
Editor is loading...
Leave a Comment