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 7765071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:04:58+00:00 2026-06-01T15:04:58+00:00

I am using basic code to highlight the text within a text field when

  • 0

I am using basic code to highlight the text within a text field when the user clicks in it:

<input type="text" id="search_for" name="searchTerm" onclick="this.select()">

Which is great, but you only have the choice to delete, meaning you can’t actually click in the middle of the selected text to add something in the middle of words/characters already in there.

Scenarios… if a user does a search for “red car”, they should be able to click in the box, its hightlighted, so hit delete and search for “blue car”. Or, they might want to click in the input and change their search to “big red car”.

Is it possible to click then unset the highlight by clicking again? Or what other method could I use?

Or should I select the field on page load, then click to un-select? Is that even possible?

I’ve searched extensively for this but no luck as yet.

  • 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-06-01T15:04:59+00:00Added an answer on June 1, 2026 at 3:04 pm

    You could keep track of the number of clicks in the input and basically toggle select() vs focus(). It may not be exactly what you are referring to, but it is something you could do.

    See working jsFiddle demo.

    HTML:

    <input type="text" 
           id="search_for" 
           name="searchTerm" 
           onclick="searchForClick(this);" 
           value="text text text text" />​
    

    JavaScript:

    searchForClickCount = 0;
    
    function searchForClick(el) {
    
        if (searchForClickCount === 0) {
            el.select();
            searchForClickCount++;
        } else if (searchForClickCount >= 0) {
            el.focus();
            searchForClickCount = 0;
        }
    
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If i was using this basic AJAX jQuery code: $.ajax ({ type: POST, url:
Does anyone know if there is an sample code for using Visual Basic to
Below is a basic code bit in as3 flash.A simple video streaming example using
I have the following basic code to read a text file from a StreamReader:
When I compiled a code using the array name as a pointer, and I
Hai I used basic code for adwhirl to display ads by using AdWhirl. I
I am currently using TextMate for OS X to create basic Ruby code (still
I am using the basic upload code from the w3schools website but I would
I have some pretty basic code to capture a still image using AVFoundation. AVCaptureDeviceInput
I have created an ActiveX control using C++. I use Visual Basic code 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.