Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:15:15+00:00 2026-05-27T22:15:15+00:00

essentially I have a textbox on my webpage, and I’m trying to add a

  • 0

essentially I have a textbox on my webpage, and I’m trying to add a “clear” button like in iOS. I have a normal input, and an img tag (with the reset button). So far, I’ve used CSS relative positioning to make it look like the image is inside the textbox.

I’ve set the image to disappear when the text field loses focus (onfocus/onblur for the input) with javascript. I’ve got a few problems:

  1. The onclick code never executes for the img tag because it goes away right when the input loses focus. (fixed with onmousedown but I’d like a more elegant solution)

  2. I can’t seem to refocus the text input after click, using document.getElementById(‘searchbox’).focus(); (I checked the id is correct).

So I’m thinking I’m not doing this the best way, I’m wondering if I can somehow group the input and reset button better (they’re both in the same li right now)? And while I’m at it, is there a way to set the hide/disappear with CSS? So like with the input#searchbox:focus selector, change the properties of img#searchreset

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:15:15+00:00Added an answer on May 27, 2026 at 10:15 pm

    I created something similar for a project I was working on. The main difference is that the image was visible at all times for usability reasons.

    Grouping the input and button:

    For the first part of your question, the approach I took was to use a parent container to hold both the textbox and the button. This will allow you to take the approach Apple took with their search. They used a css sprite (tutorial) instead of svg for the image. If you happen to be using a browser that allows you to “inspect element”, you can go to their site and see how they’re doing it.

    Basically, I recommend putting the background image on the containing element so that the textbox and the button both look as if they’re “inside the image”. Then once the textbox gains focus, you can shift the background image vertically with CSS positioning and you get the look you want.

    Hide/Disappear:

    To hide and disappear using CSS alone is not possible. You can however create two classes, one to hide and the other to show the button. Then in javascript, once the textbox gains focus, you can set the button’s visibility to “visible” and on blur, you set it to “hidden”.

    JS recommendation:

    You should look into using event listeners (tutorial) instead of the HTML attributes to detect your clicks or presses. It’s a much cleaner and more elegant approach. This is where I would say that using a framework like jQuery would make things much easier. It allows you to set event listeners and not worry about legacy browsers and varied implementations of the standard.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a Hibernate layer for a database schema I have essentially
Essentially I would like to have a messages.properties files external to the jar files
I would like to have a textbox in a Silverlight app where the user
Essentially I have a HtmlPasswordFor(m => EmployeeID), I have a button called Go. Once
Like the question says, I am trying to capture a click on a textbox
I have the following code that executes when a form submits: $('input[value=enter highlight]').val(''); Essentially,
I've got a standard TextBox control which I'm trying to have mimic the soft
I have a form which is essentially an autocomplete input box. I can get
I essentially have an array of values like this: 0.25, 0.24, 0.27, 0.26, 0.29,
Essentially I have a method of a class called killProgram, which is intended to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.