Found 6705 Articles for Javascript

How to Change a Button Text on Click Using LocalStorage in Javascript?

Aayush Mohan Sinha
Updated on 12-Sep-2023 15:05:21

216 Views

JavaScript is a famous programming language that is one of the core languages of the World Wide Web (WWW) alongside HTML and CSS. It allows the programmer to capture events and modify the Document Object Model (DOM). In this article we are going to see how we can make use of JavaScript to change the text of the button whenever it is clicked with the help of localStorage. localStorage The localStorage is a read−only property of the window interface that allows the user to store data. The saved information is kept between browser sessions. The localStorage property is like sessionStorage, ... Read More

How to Catch all JavaScript Errors and Send them to the Server?

Aayush Mohan Sinha
Updated on 12-Sep-2023 15:01:47

174 Views

JavaScript is a famous programming language that is one of the core languages of the World Wide Web (WWW) alongside HTML and CSS. It allows the programmer to capture events and modify the Document Object Model (DOM). In this article we are going to learn how we can catch all JavaScript errors and send them to the server. What is onerror? onerror is an event that is fired whenever an error occurs while loading an external file or resource or some error occurs while executing a script. Syntax onerror = (event, source, lineno, colno, error) => {}; Parameters: The ... Read More

How to Catch a ReferenceError with onerror?

Aayush Mohan Sinha
Updated on 12-Sep-2023 14:40:50

38 Views

JavaScript is a famous programming language that is one of the core languages of the World Wide Web (WWW) alongside HTML and CSS. It allows the programmer to capture events and modify the Document Object Model (DOM). In this article we are going to see how we can catch ReferenceError with the help of onerror event. What is ReferenceError? A ReferenceError is a form of error that may occur when the program tries to access a variable or object that doesn't exist. This can occur when a variable's name is spelled incorrectly or when the user attempts to access an ... Read More

How to Randomly Change Image Color using HTML CSS and JavaScript ?

Eesha Gandhi
Updated on 12-Sep-2023 12:10:34

282 Views

In this tutorial, we will look at two approaches to change the image color randomly using HTML, CSS and JavaScript. Approach 1: Using Math.random() Function We will begin by writing the HTML code and use the tag to select the target image. Then we will apply some basic some basic styles using CSS properties. In order to select colors randomly, we have to use the JavaScript Math.random() function. Math.random() generates a number at random between 0 (inclusive) and 1 (exclusive). To change the color of the image, we will use event listeners. The event listener is used to change ... Read More

How to Create StopWatch using HTML CSS and JavaScript ?

Eesha Gandhi
Updated on 12-Sep-2023 11:57:01

1K+ Views

In this tutorial, we will create a stopwatch with the functionality of start, stop and reset, using HTML, CSS, and JavaScript. We'll start by creating the stopwatch's user interface with HTML and CSS. Then, using JavaScript, we'll make the user interface functional. Creating a User Interface for the Stopwatch The first step is to make a single container that contains all of the elements. Further, we proceed to add two divs inside this container, one containing all time elements such as an hour, minutes, seconds, and milliseconds and the other div containing three buttons for the start, ... Read More

How to Set Default HTML Form Focus Without JavaScript?

Eesha Gandhi
Updated on 12-Sep-2023 10:30:39

148 Views

A HTML form is a section of a document that includes controls like text fields, password fields, checkboxes, radio buttons, a submit button, menus, and so on. It allows the user to enter any data like name, email address, password, phone number, and so on that will be sent to the server for processing. HTML forms are required if we want to collect information from site visitors. The syntax for creating a form is given below. --form elements— ExampleHere is an example showing a simple form with its default behavior. Example ... Read More

How to Add onclick in a Button using javascript?

Eesha Gandhi
Updated on 11-Sep-2023 15:55:09

3K+ Views

The onclick event generally occurs when the user clicks on an element. It enables the programmer to run a JavaScript function when an element is clicked. This event can be used to validate a form, display warning messages, and much more. This event can be added dynamically to any element using JavaScript. Except for , , , , , , , , , , and , it supports all HTML elements. In HTML, we can use the onclick attribute and associate it with a JavaScript function. For greater flexibility, we can also use JavaScript's addEventListener() method and pass a click ... Read More

How to Validate Mobile Number Length in ReactJS?

Rushi Javiya
Updated on 08-Sep-2023 12:58:57

661 Views

Nowadays, validation of mobile number input is a required feature for any application, and it requires validation of the length of the mobile number. Many apps use the mobile number for authentication purposes, sending OTP to users' mobile numbers for successful authentication. If the user enters the wrong mobile number, the app can face issues with sending OTP. So, before the user submits the mobile number for registration or authenticates the app, our app should validate the length of the mobile number. This tutorial will teach us various approaches to validating a mobile number using ReactJs. Before we start, users ... Read More

How to Validate an Email in ReactJS?

Rushi Javiya
Updated on 08-Sep-2023 12:56:23

3K+ Views

Email validation is an important feature we need to add to the authentication form. Nowadays, most applications use email and a one-time password for authentication. If the user enters the wrong email, they should not be able to authenticate their selves. Also, we need to validate the email while getting the user's email via the contact form. The user may enter the wrong email format due to some mistake. So, to correct users' mistakes, we can alert them by showing the error that you have entered the wrong email. Below, we will learn two approaches to validate the email address ... Read More

How to validate a Date in ReactJS?

Rushi Javiya
Updated on 08-Sep-2023 12:52:08

1K+ Views

Sometimes, we require to take the date from the users' string format. So, users can make mistakes while entering the date value into the input field. So, we need to validate the date string at our end in the application code. Below, we will learn various solutions to validate the date in ReactJs. Use the Validator NPM Package The Validator is an NPM package that contains various methods to validate strings. For example, it contains the isDate() method, and we can validate the date string with any delimiter separated. Also, it contains the methods to validate the email and phone ... Read More

Advertisements