Shade of text box background

After clicking the submit button, I want the background color in the text-box to remain visible for at least 5 seconds.

However, it disappears immediately upon submitting.

Here is the code snippet...

<!DOCTYPE>
<html>
<head>
<title>Text Boxes With Aplhabets </title>
</head>
<body>`enter code here`

<script type="text/javascript">

 frm.alphabets.value="";
function AllowAlphabets(){
               if (!frm.alphabets.value.match(/^[a-zA-Z]+$/) )
               {

                    frm.alphabets.focus(); 
                    frm.alphabets.style.background="Red";
                    //alert("Please Enter only alphabets");
               }

}      
</script>

<form name="frm"   onsubmit="return AllowAlphabets()">
Enter Aplhabets: <input type="text" name="alphabets" />
<input type = "submit" value = "Submit">
</form>
<br;>
</body>
</html>

Answer №1

utilize the setTimeout() method

for example :

setTimeout(myFunction, 2000);

or

setTimeout(function () {

//your code goes here
}, 2000);

source : MDN

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

Different Ways to Retrieve JSON Data from AWS S3 Bucket Using Node.js

I am facing a challenge with downloading a .json file stored in an S3 Bucket using Node.js. Here is the code snippet I have written: const bucket = "s3bucketname"; const AWS = require('aws-sdk'); const S3= new AWS.S3(); exports.handler = async ...

Combine lists with floating elements positioned to the left or right

My HTML includes the following ul tag: <ul style="position:absolute"> <li>list 1</li> <li>list 2</li> <li>list 3</li> <li> list 4 <p>list 4 content goes here</p> ...

What is the best way to conceal a sticky footer using another element?

I have a footer that remains fixed at the bottom of both long and short pages. Below is the CSS code for this footer: .footer{ position: absolute; bottom: 0; width: 100%; height: 100px; background-color: white; } My goal is to achieve a 'r ...

What is preventing JavaScript from parsing this specific string?

When I send a JSON encoded value from PHP to JavaScript and try to log it in the console, this is what I get: {"id":"4","username":"muzikant346","coins":"675","avatar1":"1","avatar2":"0","avatar3":"0","avatar4":"0","avatar_selected":"0"} The issue arises ...

Statically positioned column in PrimeReact's datatable achieved without utilizing jQuery

I have been looking into ways to make one of the columns in my datatable fixed. While I came across a solution using jQuery, I am interested in achieving this without relying on jQuery. Are there any tips you could offer on how to achieve this using HTML, ...

The callback keeps getting triggered repeatedly, and I'm struggling to understand the reason behind it

One of the challenges I am facing revolves around a utility function responsible for launching a child process. The goal is to halt the listening process and trigger the callback as soon as the child process outputs a specific message to stdout: export co ...

Prevent running function bodies simultaneously based on user events in JavaScript until a previously triggered execution is completed

When a user clicks on a button in my component, the doSomething function is activated. The issue I am facing is that doSomething takes between 200-1100ms to finish execution and change state. What complicates matters is that when the button is clicked rapi ...

Unable to execute webdriverIO scripts on Chrome browser with version 108

After updating my Chrome browser to Version 108.0.5359.72, I encountered a problem while running webdriverIO scripts. Despite updating the driver, I kept receiving the following error message: "ERROR webdriver: WebDriver Error: Could not start a new sessio ...

conceal the act of pushing

After adding a property in a push function to toggle between hiding the label and showing the input, there is a need to reverse this action when the user clicks on Save changes. This can be achieved by using the ng-hide directive. <tr ng-repeat="pe ...

Is the Utilization of Inline JavaScript in HTML Attributes by Angular considered a "good practice"?

While going through the Angular tutorials, I found a lot to like. However, I couldn't help but wonder if "ng-click" is not essentially just an inline onClick function. My understanding was that the JavaScript community frowned upon using inline JavaSc ...

Rails: carousel stops working upon returning to the homepage

My website's carousel is causing me some trouble. When I visit 127.0.0.1:3000/, the carousel works perfectly fine. However, if I navigate to the products page and then return to the home page using the nav-bar, the carousel does not load on the home p ...

What is the best way to create a JQuery click event that applies to every button on my webpage?

I am working on a website settings page where logged-in users can edit the content displayed on the public page. I have a form that uses AJAX to update the content when submitted. My main question is how to modify the code so it can determine which text b ...

Utilizing a mouse-over script for image popup alignment

I recently came across the mouse over script below on a website, and I must say it works really well and is very easy to use. The only issue I have with it is the placement of the image. Currently, the image follows the cursor as it moves. Question: Is th ...

The context parameter in Next Js' getStaticProps method gives back the values of "locales", "locale", and "defaultLocale" as undefined

Having an issue with the context parameter from Next Js's getStaticProps function. When I console log it, I am getting "{ locales: undefined, locale: undefined, defaultLocale: undefined }". Even though I am using getStaticProps inside the pages folde ...

Can the :after pseudo-element be modified when hovering, except when hovering over the after element itself?

Currently, my CSS code looks like this: class-name:hover:after {} Although it works well, the hover effect triggers even when hovering over the after portion of the element. Is there a way to modify the code so that the :hover only applies when hovering ...

I desire for an element to reduce in size relative to the amount of space occupied by the adjacent element on the screen

Is there a better solution to adjust the size of the divider line on the picture based on the All publications link? I have implemented it this way so far, but I'm open to other suggestions. https://i.sstatic.net/UBl1n.png @media (max-width: 767px) ...

Styling for a table with one column set to a fixed width, one column designated as small, and the rest of the

Creating a table with fixed width first column, text-contracting second column, and equally splitting remaining space for the rest seems to be a challenge. Check out this fiddle for my current attempt: http://jsfiddle.net/B8LnP/ Two key issues to observe ...

Poll # Warning: The variable "poll" has not been defined. Please check the code in H:xampphtdocsuserpollvote_form.php on

This is an HTML form for displaying a poll question. I am encountering errors with the variables 'poll' and 'question', as I am new to PHP. Can someone please assist me in resolving this issue? <html> <head></head&g ...

JavaScript: Receiving Varied Outputs from Comparable Functions

Here are two code snippets that contain an object and a function, both with identical content. They should theoretically return the same value. The only difference between the two is the presence of brackets and an 'else' statement in the 'f ...

Try utilizing a distinct value for searching compared to the one that is shown in Material UI's Autocomplete feature for React in JavaScript

I'm currently utilizing the <AutoComplete /> component offered by Material UI. It prescribes the following organization for the options const options = [ { label: 'The Godfather', id: 1 }, { label: 'Pulp Fiction', id: 2 } ...