Skip to content

Instantly share code, notes, and snippets.

@rexrony
Forked from charleslouis/valueToPlaceholder.js
Created July 27, 2016 07:18
Show Gist options
  • Select an option

  • Save rexrony/8558864386163f67f0783450e236adca to your computer and use it in GitHub Desktop.

Select an option

Save rexrony/8558864386163f67f0783450e236adca to your computer and use it in GitHub Desktop.
#value #placeholder #attribute #html5 #form #input #inputfiled #jquery
function valueToPlaceHolder(divId){
// this function creates a placeholder based on the attribute 'value' of this same input text field
//once done, it removes the 'value' attribute
// it is useful for cforms II plugin cos placholder are not available, while default value attr are
// THIS :
// <input xxx value="Prénom - First name" xxx>
// would return :
// <input xxx placeholder="Prénom - First name" xxx>
// see http://stackoverflow.com/questions/11432144/change-value-to-placeholder-input-field
if( document.getElementById(divId) ){
$('input[type="text"]').each(function() {
var $this = $(this);
$this.attr('placeholder', $this.attr('value')).removeAttr('value');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment