SOLVED

Insert Email Address into JavaScript on Form Submission

Go to solution
Anonymous
Not applicable

Insert Email Address into JavaScript on Form Submission

We're looking to run a peice of JavaScript on one of our form submission confirmation pages.  We want to take some data submitted by the customer on the form (e.g. email address) and insert it into the JavaScript for processing.  Is there a way to do this?
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Insert Email Address into JavaScript on Form Submission

Yes, we have a java script that validates the domain of the email address that is submitted in a form.  Below is the script we are running with an abridged invalid domain list.  Hope this helps.

<style type="text/css">
span.mktFormMsg {
display:block !important;
left:5px !important;
position: relative !important;
}
</style>

<script type="text/javascript" src="/js/public/jquery-latest.min.js"

language="JavaScript"></script>
<script type="text/javascript">
// set no conflict mode for jquery
var $jQ = jQuery.noConflict();
//edit this list with the domains you want to block
var invalidDomains = ["@123mail.org","@aol.com"];

function formSubmit(elt) {
// run the custom validation. If it succeeds, run the Marketo validation
if (!isEmailGood()) {
Mkto.setError($jQ("#Email ~ span").prev()[0],"Please enter a business address, not one from a public service");
return false;
} else {
Mkto.clearError($jQ("#Email ~ span").prev()[0]);
}
return Mkto.formSubmit(elt);
}

function isEmailGood() {
for(i=0; i < invalidDomains.length; i++) {
if ( $jQ("#Email[value*=" + invalidDomains[i] + "]").length > 0) {
return false;
}
}
return true;
}
</script>

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Re: Insert Email Address into JavaScript on Form Submission

Yes, we have a java script that validates the domain of the email address that is submitted in a form.  Below is the script we are running with an abridged invalid domain list.  Hope this helps.

<style type="text/css">
span.mktFormMsg {
display:block !important;
left:5px !important;
position: relative !important;
}
</style>

<script type="text/javascript" src="/js/public/jquery-latest.min.js"

language="JavaScript"></script>
<script type="text/javascript">
// set no conflict mode for jquery
var $jQ = jQuery.noConflict();
//edit this list with the domains you want to block
var invalidDomains = ["@123mail.org","@aol.com"];

function formSubmit(elt) {
// run the custom validation. If it succeeds, run the Marketo validation
if (!isEmailGood()) {
Mkto.setError($jQ("#Email ~ span").prev()[0],"Please enter a business address, not one from a public service");
return false;
} else {
Mkto.clearError($jQ("#Email ~ span").prev()[0]);
}
return Mkto.formSubmit(elt);
}

function isEmailGood() {
for(i=0; i < invalidDomains.length; i++) {
if ( $jQ("#Email[value*=" + invalidDomains[i] + "]").length > 0) {
return false;
}
}
return true;
}
</script>