Skip to content

Instantly share code, notes, and snippets.

@noahub
Last active October 2, 2015 23:10
Show Gist options
  • Save noahub/2ec59cd9ff5369fd238f to your computer and use it in GitHub Desktop.
Save noahub/2ec59cd9ff5369fd238f to your computer and use it in GitHub Desktop.
Field Values to Upper Case
<script>
//Replace #lp-pom-form-17 with your form's ID and 'email' with your field name.
//To convert field values to lower case, simply replace 'toUpperCase()' with 'toLowerCase()'
//To convert field values to Title Case, simply replace 'toUpperCase()' with 'replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});'
$("#lp-pom-form-17 input[name=email]").val(function () {
return this.value.toUpperCase();
})
</script>
//To execute the above function on form submit, use @johnnyopao's script like so:
<script type="text/javascript">
function yourSubmitFunction(e, $) {
e.preventDefault();
//CUSTOM CODE HERE
//Replace #lp-pom-form-17 with your form's ID and 'email' with your field name
$("#lp-pom-form-17 input[name=email]").val(function () {
return this.value.toUpperCase();
// If your code is asynchronous, call this final line in your callback instead
$('.lp-pom-form form').submit();
}
lp.jQuery(function($) {
$('.lp-pom-form .lp-pom-button').unbind('click').bind('click.formSubmit', function(e) {
if ( $('.lp-pom-form form').valid() ) yourSubmitFunction(e, $);
});
$('form').unbind('keypress').bind('keypress.formSubmit', function(e) {
if(e.which === 13 && e.target.nodeName.toLowerCase() !== 'textarea' && $('.lp-pom-form form').valid() )
yourSubmitFunction(e, $);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment