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

  • Home
  • SEARCH
  • 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 7524941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:11:53+00:00 2026-05-30T03:11:53+00:00

I have an ‘onclick’ event handler for a div and the div has a

  • 0

I have an ‘onclick’ event handler for a div and the div has a nested read-only text field whose text font changes from normal to bold when selected inside the onclick handler:

 <div class="itemlistRowContainer" id="topmostDiv_ID" onclick="handleRowClick(this);">
    <input type="text" size="30" maxlength="50" id="itemName_id"
           name="itemName" value="$itemname" readonly="readonly"
           class="itemListReadonlyTextFieldUnselected"></input>
 </div>

Here is the onclick handler:

  function handleRowClick(theElement)
  {
      var childTextElementArrayOfSizeOne = theElement.getElementsByTagName("input");
      var theTextField = childTextElementArrayOfSizeOne[0];

      theTextField.className = "itemListReadonlyTextFieldSelected";
  }

Here’s the itemListReadonlyTextFieldSelected CSS class:

   .itemListReadonlyTextFieldSelected
   {
        font-weight: bold;
        color: RGB(255,0,0);
   }

I have several of these div-with-nested-readonly-text-field on my page.

When the user clicks on one of them, the above onclick handler successfully changes the nested text input’s font to bold and color red. So the selecting part — bold+red text — works fine. But I need to de-select the old selection when the user clicks elsewhere.

So my question is — how can I keep track of the ‘currently selected div+text input’ item — so that when a different div+text input is clicked on, I can change back the previously selected div+text input to black, not-bold text, using this style?

   .itemListReadonlyTextFieldUnelected
   {
        font-weight: normal;
        color: RGB(0,0,0);
   }

I immediately thought "I’ll just save the ‘currently selected’ div and text input DOM elements in my SESSION – ahh nope this is client side javascript." Session variables are my go-to for stuff like this on server-side code.

My current technology requirements are php, javascript and html (jquery = no.)

What’s a good way to keep track of the previously selected div+text input?

A brute-force method would be to traverse the tree of ELEMENTs on the page and find the one div that has a nested text element whose className = "itemListReadonlyTextFieldSelected" but I’d rather smash my big toe with a gott-dang sledgehammer than have someone during a code review slap me upside the head after seeing something like that.

  • 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-30T03:11:55+00:00Added an answer on May 30, 2026 at 3:11 am

    How about assigning it to a variable?

    var currentlySelectedTextElement;
    
    function handleRowClick(theElement)
    {
        // un-highlight the currently highlighted element
        if (currentlySelectedTextElement){
            currentlySelectedTextElement.className = "";
        }
    
        var childTextElementArrayOfSizeOne = theElement.getElementsByTagName("input");
        var theTextField = childTextElementArrayOfSizeOne[0];
    
        theTextField.className = "itemListReadonlyTextFieldSelected";
    
        // save the reference so you can un-highlight it later
        currentlySelectedTextElement = theTextField;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have the following text file: <div> <asp:HyperLinkField HeaderText=Hello World of Regular Expression /> </div>
Have an app that can use tts to read text messages. It can also
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have a script to add / remove options from a select field -- the
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
Have I understod the following right? font-family:sans-serif; Above will result in the default sans-serif
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution

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.