I am working with a form, and the front end devs have default text inside of the textboxes. For instance, the zip code input box does not have a label, however, there is prepopulated text in the boxes. here is an example of an input
<input id="place" name="place" type="text" value="(City, State or Zip Code)"
This particular input is on a search form. This input, along with other inputs, are being passed to the server via ajax. When the results arrive at the server, there is a post variable called “place”, and if unchanged by the user, the value is “(City, State or Zip Code)”. I am wondering if there is a front end solution that I can easily implement to make it so that if the default text is not changed (nothing was entered into the input), the server will see this $_post variable as empty. I already know that I could check on the server and see
if $_post[place] == "(City, State or Zip Code)"
//place is empty, omit it from the search query
but I am looking for a better way, if a better way exists.
How do you deal with default input text?
Thanks!
edit: To summarise, I am looking for a way to pass this and other inputs to the server as blank if they are not changed by the user. I would like to do it without using the aforementioned if $_post[place]…… on the serverside, and if possible, the client side as well.
You should be using placeholder attribute for that: http://www.w3schools.com/html5/att_input_placeholder.asp
This will display the placeholder value, but won’t send it to server.
And let older browsers gracefully degrade to empty input or fallback to JS if you want (how to check if it’s supported: http://davidwalsh.name/html5-placeholder).