Insert Email Address into JavaScript on Form Submission | Community
Skip to main content
March 14, 2013
Solved

Insert Email Address into JavaScript on Form Submission

  • March 14, 2013
  • 1 reply
  • 961 views
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?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by
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>

1 reply

Accepted solution
March 14, 2013
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>