Javascript Articles

Page 474 of 534

How to make my textfield empty after button click in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

To clear a text field after a button click in JavaScript, you can use the onclick event with document.getElementById().value = '' to reset the input field's value to an empty string. Syntax document.getElementById("fieldId").value = ''; Example Clear Text Field Example Clear Text function clearTextField() { ...

Read More

How can we invoke the parent's method, when a child has a method with the same name in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

When both parent and child classes have methods with the same name, JavaScript provides several ways to invoke the parent's method from the child class or externally. Syntax To call a parent method when overridden by a child class: // From within child class super.methodName() // From outside using call() ParentClassName.prototype.methodName.call(childObject) Using super Keyword (Recommended) The super keyword is the modern way to call parent methods from within a child class: class Parent { constructor(value) { this.value = ...

Read More

Display the dropdown's (select) selected value on console in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

In JavaScript, you can capture the selected value from a dropdown (select element) and display it in the console using the onchange event and console.log(). HTML Structure Here's a basic dropdown with an onchange event handler: Javascript MySQL MongoDB Java Complete Example Dropdown Selected Value Select a Subject: ...

Read More

Display the Asian and American Date Time with Date Object in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

JavaScript's Date object provides powerful timezone handling through the toLocaleString() method. You can display dates and times for different regions by specifying timezone identifiers. Syntax new Date().toLocaleString("en-US", {timeZone: "timezone_identifier"}); Parameters locale: Language and region format (e.g., "en-US", "en-GB") timeZone: IANA timezone identifier (e.g., "Asia/Kolkata", "America/New_York") Asian Time Zone Example // Display current time in Asian timezone (India) var asianDateTime = new Date().toLocaleString("en-US", { timeZone: "Asia/Kolkata" }); console.log("Asian Date Time (India):"); console.log(asianDateTime); // Convert to Date object for further processing var asianDateObject = new ...

Read More

How can I filter JSON data with multiple objects?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 17K+ Views

To filter JSON data with multiple objects, you can use the filter() method along with comparison operators. This allows you to extract specific objects based on criteria. Syntax array.filter(callback(element, index, array)) Example: Filter by Single Property const jsonObject = [ { studentId: 101, studentName: "David" }, { studentId: 102, ...

Read More

Multi-selection of Checkboxes on button click in jQuery?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 521 Views

Multi-selecting checkboxes is a common requirement in web forms. This can be achieved using jQuery to toggle all checkboxes with a single button click. Approach We'll use jQuery's prop() method to set the checked property of multiple checkboxes and toggleClass() to manage the button state. Example Multi-selection Checkboxes .changeColor { ...

Read More

How to avoid inserting NULL values to a table with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 655 Views

When building dynamic tables with JavaScript, it's important to validate user input and prevent NULL values from being inserted. This ensures data integrity and provides a better user experience. Understanding NULL Validation In JavaScript, we need to check for null, undefined, and empty strings before inserting values into a table. The basic condition structure is: while (!(variable1 == null || variable2 == null || variable3 == null)) { // Insert values only when none are null } Complete Example with Validation ...

Read More

How to move all capital letters to the beginning of the string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 345 Views

To move all capital letters to the beginning of a string in JavaScript, we can use the sort() method with a regular expression to identify uppercase letters and rearrange them. Let's say we have the following string: my name is JOHN SMITH We'll use sort() along with the regular expression /[A-Z]/ to move all capital letters to the beginning of the string. Example var moveAllCapitalLettersAtTheBeginning = [...'my name is JOHN SMITH'] .sort((value1, value2) => /[A-Z]/.test(value1) ? /[A-Z]/.test(value2) ? 0 : -1 : 0).join(''); console.log("After moving all capital letters at the beginning:"); console.log(moveAllCapitalLettersAtTheBeginning); ...

Read More

Check if value of an object of certain class has been altered in JavaScript and update another value based on it?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 92 Views

In JavaScript, you can monitor changes to object properties and automatically update dependent values using getters and setters. This approach allows you to create reactive properties that respond when other properties change. Basic Property Monitoring with Getters The simplest approach uses getter methods to access current property values: class Student { constructor(studentMarks1, studentMarks2) { this.studentMarks1 = studentMarks1; this.studentMarks2 = studentMarks2; var self = this; ...

Read More

Check for illegal number with isNaN() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 245 Views

In JavaScript, isNaN() function checks if a value is "Not a Number" (NaN). It's commonly used to validate numeric operations and detect illegal numbers in calculations. What is NaN? NaN stands for "Not a Number" and is returned when a mathematical operation fails or produces an undefined result, such as multiplying a string with a number. Syntax isNaN(value) Parameters value: The value to be tested. If not a number, JavaScript attempts to convert it before testing. Return Value Returns true if the value is NaN, false otherwise. Example: Detecting ...

Read More
Showing 4731–4740 of 5,340 articles
« Prev 1 472 473 474 475 476 534 Next »
Advertisements