Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing input placeholder on a printable version of an html page

I have a form with input fields. Each input field has a placeholder attribute. There is also a link displaying the printable version of the same form.

My problem is that if I leave the placeholder attribute unchanged and the input field is empty, then the placeholder is actually printed, which is not very good.

I am looking for a way to resolve this unfortunate behavior. Right now, the only thing I can think of is traverse the DOM in javascript and remove all the placeholder attributes when the printable version is given. Of course, when reverting back to the normal page view, the placeholder attributes must be restored too.

This is not hard, but is also not very elegant. I wonder if there is a better solution.

like image 935
mark Avatar asked May 11 '13 03:05

mark


People also ask

What is input placeholder in HTML?

Definition and Usage The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format). The short hint is displayed in the input field before the user enters a value.

How do I create a placeholder for a selection box in HTML?

Answer: Use the disabled and selected Attribute There is no attribute like input's placeholder for select box dropdown. However, you can create similar effect by using the HTML disabled and selected attribute on a <option> element that has empty value.


2 Answers

In most modern browsers, you should be able to hide placeholders when printing, via some non-standard CSS selectors.

@media print {
  ::-webkit-input-placeholder { /* WebKit browsers */
      color: transparent;
  }
  :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
      color: transparent;
  }
  ::-moz-placeholder { /* Mozilla Firefox 19+ */
      color: transparent;
  }
  :-ms-input-placeholder { /* Internet Explorer 10+ */
      color: transparent;
  }
}

(or color: white, etc.)

Selector list stolen from: Change an HTML5 input's placeholder color with CSS

like image 152
Paul Roub Avatar answered Oct 11 '22 05:10

Paul Roub


or you can move it outside the visible area of the parent element by text-indent or some other overflowy hack

like image 25
mike nvck Avatar answered Oct 11 '22 06:10

mike nvck