2

I would like to use jQuery code to simulate placeholder text for old browsers. I have found a number that are great candidates, and work well. However, one issue is that the solutions tend to input the placeholder text as the cell value (until user input). This means that if an html form is submitted with any fields unchanged, then the placeholder text is submitted as if it is user input.

Are there any jQuery placeholder solutions that solve this?

Cheers

jay
  • 12,066
  • 16
  • 64
  • 103

3 Answers3

4

I use jquery placeholder . U should try it

https://github.com/prantor19/jquery-placeholder

Arif
  • 978
  • 12
  • 29
0

Check if placeholder value is present before form is send and remove it:

$('form').submit(function(){
   if($('#someinput').val() == 'placeholder value') {
     $('#someinput').val('');
   }
});
Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105
  • i can't seem to get the contents to run when the form is submitted. it is submitted remotely, is that an issue? – jay Jan 20 '12 at 19:23
  • What do you mean by 'submitted remotely'? By javascript rather than directly by user? `submit` trigger should fire anyway. – Konrad Dzwinel Jan 20 '12 at 19:32
  • actually, i think .submit is a jquery method to cause a form to submit. I don't think that it reacts when a form is submitted.. http://api.jquery.com/submit/ I think a different method is required – jay Jan 20 '12 at 19:34
  • It says in docs: `Bind an event handler to the "submit" JavaScript event, OR trigger that event on an element.`, mind the `OR` :) – Konrad Dzwinel Jan 20 '12 at 19:37
  • Check if your code is inside `$(document).ready(function(){ -code here- });`, that's a common thing to forget about. – Konrad Dzwinel Jan 20 '12 at 19:38
  • yeah.. i don't know if i'm doing something wrong. I do have it inside the document ready thing. If I write an alert("hi") i get the alert if it's outside of the form submit part. But I can't get any code to execute when the form is submitted.. – jay Jan 20 '12 at 19:48
  • yeah my problem had to do with loading the form after initial pageload, not with your code. thanks for the help. – jay Jan 20 '12 at 19:57
0

Just off the top of my head, what about something like this (jsfiddle).

magicalex
  • 917
  • 7
  • 11
  • this could work.. but would require that I change all of the forms - I will perhaps try to write some jquery code to create these elements if there is no placeholder support – jay Jan 20 '12 at 19:49