Auto-prepend HTTPS to URLs

Experimental Snippet 🧪

Auto-prepend “https://” to URLs in Website fields.

Code

Filename: gw-auto-prepend-https.js

/**
 * Gravity Wiz // Gravity Forms // Auto-prepend HTTPS to URLs
 * https://gravitywiz.com/
 *
 * Experimental Snippet 🧪
 *
 * Auto-prepend "https://" to URLs in Website fields.
 */
// Update "1" to your field ID.
$( '#input_GFFORMID_1' )
	.on( 'focus', function() {
		if ( $( this ).val() === '' ) {
			$( this ).val( 'https://' );
		}
	} )
	.on( 'keyup', function() {
		if ( $( this ).val() === 'https:/' ) {
			$( this ).val( 'https://' );
		} else if ( $( this ).val().indexOf( 'https://' ) !== 0 ) {
			$( this ).val( 'https://' + $( this ).val() );
		}
	} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.