Is there an easy way to adjust the Forecolor of a Textbox when it is clicked on?

There are two textboxes with default values in forecolor:#999999. I want these default values to clear and the forecolor to change to black when the textbox is clicked, like watermarking. However, I am not utilizing Ajax for this. Can someone please assist me with achieving this functionality?

Answer №1

To ensure accessibility for keyboard users tabbing through the document, it is recommended to utilize the onfocus and onblur events instead of relying solely on click events.

let userInput = document.getElementById("userInput");
userInput.onfocus = function () {
    if (this.value === "Default User Input") {
        this.value = "";
        this.style.color = "#000";
    }
}
userInput.onblur = function () {
    if (this.value === "") {
        this.value = "Default User Input";
        this.style.color = "#999";
    }
}

View a live demo here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining the keys of two objects in JSON

console.log(a) ; // output in console window= 1 console.log(b);// output in console window= 2 var c = {a : b};// Is there a better way to do this? var d = JSON.stringify(c); d = encodeURIComponent(d); I want the final value of d to be {1:2}. ...

What is the best way to detect when a user manually changes a dropdown selection?

Is there a way to detect when a user changes a dropdown option manually, rather than when the page loads and the default value is set? I attempted using e.originalEvent, but it didn't work as expected. $(self.options.selectChange).change(function (e ...

Retain and Showcase the latest User Input

The Objective: Design a "Golf Scorecard" for a group outing with friends where each player can log their scores for each hole. For example, as Golfer Alex plays, someone else in the group can input his score under "Hole 1". The scores will be saved on the ...

Troubleshooting: jQuery Text Limiter malfunctioning

I am currently having trouble with implementing the textLimiter jQuery class from http://plugins.jquery.com/project/jQueryTextLimiterCounter. Despite following the demo as a guide, I can't seem to make it work. Here is what I have done so far: Master ...

Trouble with applying CSS class to checkboxlist

I am trying to display a border around each checkbox item in a checkboxlist. I believe that it can be achieved by setting the td cssclass as the checkboxlist saves items in td. However, the code I tried below is not working. Here is the ASPX code: < ...

Implementing pagination in a node.js application using pg-promise and fetching data from

Upon reviewing the documentation at https://github.com/vitaly-t/pg-promise/wiki/Data-Imports, I found a comprehensive guide on importing data using pg-promise. Although the example provided works for the showcased scenario, I am unsure how to adapt it to ...

Determine if the html element is wrapping to a new line when zoomed in or when the text size on Windows is increased

My webpage has 2 labels displayed side by side, but due to the system text size being set at 150% (which is recommended) in Windows, the second label does not have enough space and gets pushed below the first label. I am looking for a way to determine if t ...

Ways to access the values of checkboxes that are initially checked by default

Recently, I was working on a project that involved multiple checkboxes. My goal was to have the checkboxes pre-checked with values in the form (using reactive form). Users should be able to unselect the boxes as they wish and the data would be stored accor ...

One way to concatenate texts in an array of dictionaries while keeping the order intact in JS/React is to compare and match specific key-value pairs

My dataset looks something like this: Record= [ { "tid":1, token_text": "Canis", "spanid": 1, "label": "Name" }, { "tid":2, "token_text": "Familiaris", "spanid": ...

What is the best way to configure npm test for running cucumber tests across different platforms?

During my exploration of Jasmine, I found that I could easily include the following snippet in my package.json: "scripts": { "test": "jasmine" }, By executing npm test from a Windows command prompt, I was able to run my Jasmine tests using npm. Howe ...

Send an ArrayList to jQuery Flot

Good day. Apologies for any language barriers as English is not my first language. I am a novice in [see tags] and I have a web application that gathers a date and a serial number to execute a SQL query. The query returns some data (measurement values an ...

The angularjs script encountered an issue when trying to access the property $scope.dropdownfield, as

I am working on a registration form page that includes a person_id field and a drop down list called condition_code_1. The person_id field is mandatory, while the condition_code_1 drop down list is optional for the user to select. The values for the drop d ...

Executing a JavaScript script from a C# script: A step-by-step guide

Greetings all! I am currently engrossed in a school project that requires me to populate a paragraph element with data from a table in my database. Initially, I attempted to achieve this task using JavaScript, but due to the connection script being in C#, ...

Is it possible to create dynamic animations with SVG files?

I am currently in the process of coding my website, and I came up with an exciting idea to animate my navigation bar within an SVG container. With its naturally wavy design, I aim to achieve a sweeping wave effect similar to the intro animation on Discord. ...

Transform the entire content with a simple click on input labels

tab3 > brand-sidebar-wrapper > lacquer-type-wrapper > input Whenever I click on the input labels, the .content div moves to the top and leaves a lot of space at the bottom. I have attempted to modify the JavaScript code, but the issue seems to b ...

Using Jquery to select an HTML <option> element

How can I correctly select any of these options using Jquery? <select> <option id="x" >A</option> <option>B</option> <option>C</option> <option>D</option> </select> <div id="one">& ...

Utilizing the power of combined variables in Javascript

Is there a method to incorporate variables in each loop of a javascript loop? For instance, if I were to insert this code into a loop if (e1) {item_text += '{id:"' + id[1] + '",lvl:' + e1lvl + '},<wbr>'} if (e2) {item_ ...

Changing the value of an element in an array at a specific index using Mongoose and MongoDB

Within my database, I have a field in the schema known as: priority_data: [ String ] This is a collection of data that holds priority information. An illustration of what could be stored in this field is: "priority_data": ["Photo","Video","Music"] The o ...

Tips for modifying jsFiddle code to function properly in a web browser

While similar questions have been asked before, I am still unable to find a solution to my specific issue. I have a functional code in jsFiddle that creates a table and allows you to select a row to color it red. Everything works perfectly fine in jsFiddle ...

Testing the functionality and performance of JavaScript and HTML across numerous webpages using automated tools

Operating a webstore means offering several products to our customers. The checkout process is divided into four separate pages where users must enter their address, select a delivery method, and confirm their order across various URLs. Communication with ...