This is a program which works as a Placeholder in HTML. Placeholder in html displays text in Gray color and as soon as any person starts typing in the text box the text written as “Enter Name” disappears and the text which the user types in comes in black text and if the user deletes all the contents and comes from the text box and leaves the textbox blank, again the text “Enter Name” appears in the text box with the washed out colour. In this program taking the help of JavaScript we have tried to complete the same task using document.getElementById(“txt”).style.color property. On the load event of the page we have called fun_load function which would make the text box carry the text “Enter Name” by default and this text would have gray color. Then on focus event of the text box the function fun_focus would check if the Text box already contains any text other than “Enter Name”. If it contains “Enter Name” that means the user has not typed in any text. So the “Enter Name” would disappear and would allow the user to type in any text. If the user leaves it empty then the text “Enter Name” would again appear in gray color.

Author: Gajendra Sharma