Object Oriented Programming Articles

Page 93 of 589

How to add form validation for empty input fields with JavaScript?

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

Form validation ensures users provide required information before submitting. JavaScript allows client-side validation to check for empty input fields and provide immediate feedback. Basic Empty Field Validation Here's a complete example that validates empty input fields: Form Validation Example JavaScript Empty Input Field Validation Name: ...

Read More

How to create a filter list with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 601 Views

JavaScript filter lists allow users to search and filter through data dynamically. This is commonly used for search functionality in websites and applications. Complete HTML Example * { box-sizing: border-box; } .searchInput { width: 100%; font-size: 16px; ...

Read More

JavaScript symbol.@@toPrimitive() function

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 182 Views

The Symbol.toPrimitive method defines how an object should be converted to a primitive value when used in operations that require type coercion. This method is called automatically by JavaScript when an object needs to be converted to a primitive type. Syntax object[Symbol.toPrimitive](hint) The hint parameter specifies the preferred type of conversion: "number" - when numeric conversion is preferred "string" - when string conversion is preferred "default" - when no specific preference (used in == comparison) Basic Example Symbol.toPrimitive ...

Read More

JavaScript Auto-filling one field same as other

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 428 Views

Auto-filling form fields is a common requirement in web forms, especially when users need to copy address information between billing and shipping sections. This can be achieved using JavaScript event listeners and form field manipulation. Example body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; padding: 20px; } ...

Read More

JavaScript Const

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 351 Views

The JavaScript const declaration creates variables that cannot be reassigned to another value or redeclared later. It was introduced in ES2015 (ES6) and provides block scope like let but with immutable binding. Syntax const variableName = value; Basic const Example body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } Const Example Try ...

Read More

JavaScript Convert an array to JSON

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 2K+ Views

An array is a special object in JavaScript that stores multiple types of values, including integers, strings, and floats simultaneously. JSON (JavaScript Object Notation) is a lightweight data format used to represent structured data, commonly used for transmitting data between servers and web applications. In this article, we'll explore how to convert a JavaScript array into JSON format using the JSON.stringify() method. Understanding JSON.stringify() The JSON.stringify() method converts a JavaScript value or object into a JSON string. Since arrays are objects in JavaScript, we can pass an array as an argument to this method. Syntax ...

Read More

JavaScript – Getting Coordinates of mouse

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 532 Views

In JavaScript, you can get the coordinates of the mouse cursor using mouse event properties. The most common approach is to use the mousemove event listener along with event properties like clientX, clientY, pageX, and pageY. Mouse Coordinate Properties Different properties provide coordinates relative to different reference points: clientX, clientY - Coordinates relative to the viewport (visible browser window) pageX, pageY - Coordinates relative to the entire document (includes scrolled areas) screenX, screenY - Coordinates relative to the user's screen offsetX, offsetY - Coordinates ...

Read More

JavaScript encodeURI(), decodeURI() and its components functions

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 379 Views

JavaScript provides four essential functions for handling URI encoding and decoding. The encodeURI() function encodes complete URIs while preserving structural characters, whereas encodeURIComponent() encodes URI components including all special characters. Understanding the Functions The encodeURI() function encodes special characters in a URI except for reserved characters like , / ? : @ & = + $ # which are essential for URI structure. The encodeURIComponent() function encodes URI components by encoding all special characters including the reserved ones. The corresponding decode functions decodeURI() and decodeURIComponent() reverse the encoding process. Syntax encodeURI(uri) decodeURI(encodedURI) encodeURIComponent(uriComponent) decodeURIComponent(encodedURIComponent) ...

Read More

JavaScript Error message Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 273 Views

The message property of JavaScript Error objects contains a human-readable description of the error. It's automatically set when an error occurs and can also be customized when creating custom errors. Syntax error.message Example: Accessing Error Message JavaScript Error message Property body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; ...

Read More

JavaScript Error name Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 232 Views

The name property of JavaScript Error objects identifies the type of error that occurred. It returns a string representing the error's name, which helps in debugging and error handling. Syntax error.name Common Error Names Different error types have specific names: ReferenceError - Variable or function not defined TypeError - Wrong data type used SyntaxError - Invalid syntax RangeError - Number out of range Example: Displaying Error Names Error Name Property ...

Read More
Showing 921–930 of 5,881 articles
« Prev 1 91 92 93 94 95 589 Next »
Advertisements