How Do You Have Text Fields That Have Hints (Suggested Text)?

Problem scenario
You are using PHP files (with HTML).  You have text fields that are blank by default.  These fields accept user input from the keyboard.  You want the clear text fields to have suggested text by default (to help explain to the user the type of input that is appropriate or to remind the user of content restrictions).  How do you do this?

You have a field that requests text like this HTML code (in a .php file):

<html>
<body>
<form action="anotherpage.php" method="post">

Type in text here: <input type="text" name="table"> <br>

</form>
</html>
</body>

Solution
Use the "placeholder" attribute (essentially a keyword) in this fashion (in a .php file):

<html>
<body>
<form action="anotherpage.php" method="post">

Type in text here: <input type="text" name="table" placeholder="Very cool text"> <br>

</form>
</html>
</body>

Now "very cool text" will be visible in light gray in the text field.  The "placeholder" attribute of an input tag will not work with IE version 9 or older versions.  This attribute was introduced in HTML5.  (To learn more, see this link.)  The text will not register as user text if the user does not modify the text.  The text will participate in the form as if field were empty or blank in this scenario.

If you want the default text in the field to participate in the form as if the user typed it in, this is possible.  The text will be black instead of light gray.  Use "value" instead of "placeholder" in the HTML code.

Leave a comment

Your email address will not be published. Required fields are marked *