Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Text in Searchbox

Featured Replies

Hi,

 

Trying to figure out how you have text appear in a search box. When you click in the box the text disappears and when you click out of it, if it's empty the word re appears.

 

Thanks.

Edited by Jejune

Its done using javascript.

You use the value attribute to set a default text in the textarea.

Then you use the onfocus() event to detect if the element is clicked and onblur() to detect if the element lost his focus.

 

Then just call a function that change the value of the textarea.

Something like:

 

javascript:

function focusit()
{
if (document.getElementById("textarea").value=="This is a textarea")
{
document.getElementById("textarea").value="";
}
}

function blurit()
{
if(document.getElementById("textarea").value=="")
{
document.getElementById("textarea").value="This is a textarea";

}


}


html:

<input type="text" id="textarea" onfocus="focusit()" onblur="blurit()" value="This is a textarea" />

Edited by Leonvv

You can try the placeholder tag or input type="search" ;)

for example:

<input type="search" name="search">
<input type="text" placeholder="Example text" name="search">

  • 4 weeks later...

Make sure that Doctype is for HTML5. for using below solution.

 

You can try the placeholder tag or input type="search" ;)

for example:

<input type="search" name="search">
<input type="text" placeholder="Example text" name="search">

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.