Issues with placeholder value

How can I write javascript that states, if an input field = this text, then empty the input before submitting?

Thank you for you help

By the way I thought that is what this was saying, but it still submits the placeholder as a value?:

$('[placeholder]').parents('form').submit(function() {
  $(this).find('[placeholder]').each(function() {
	var input = $(this);
	if (input.val() == input.attr('placeholder')) {
	  input.val(' ');
	}
  })
});

turns out placeholder above does work just not for IE9 or less? Any ideas?

Yes, for IE9 and below you need to do something different. I use placeholder for those browsers that can handle it, and then have a JS fallback for those that don’t recognize it.

Gotcha Ralph, so I am using Modernizer and it is inputting the placeholders just fine, however it is also using them as values, which is a big problem.

This is the code for modernizer, but it doesn’t seem to take away the value of the placeholders upon submit. Any ideas?



$(document).ready(function(){

if(!Modernizr.input.placeholder){

	$('[placeholder]').focus(function() {
	  var input = $(this);
	  if (input.val() == input.attr('placeholder')) {
		input.val('');
		input.removeClass('placeholder');
	  }
	}).blur(function() {
	  var input = $(this);
	  if (input.val() == '' || input.val() == input.attr('placeholder')) {
		input.addClass('placeholder');
		input.val(input.attr('placeholder'));
	  }
	}).blur();
	$('[placeholder]').parents('form').submit(function() {
	  $(this).find('[placeholder]').each(function() {
		var input = $(this);
		if (input.val() === input.attr('placeholder')) {
		  input.val(' ');
		}
	  })
	});

}

});


Hm, maybe this is a question for @Pullo, who’s good with jQuery. Presumably the placeholder text will only be sent if the user doesn’t type anything. You could make some fields required, I guess, to prevent default text being being sent.

Hi,
I don’t mind taking a look.
Could you post a link to a page where we can see the form in action?