Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Web Development Articles
Page 407 of 801
How to find the name and the target of a form in JavaScript?
In JavaScript, you can access the name and target attributes of HTML forms using DOM properties. These attributes help identify forms and control where form submissions open. The name attribute provides a unique identifier for the form, while the target attribute specifies where to display the response after form submission. Common target values include _self (same window), _blank (new window), _parent, and _top. Syntax To access form properties, use the following syntax: // Get form name document.getElementById('formId').name; // Get form target document.getElementById('formId').target; Example 1: Getting Form Name This example demonstrates how ...
Read MoreHow to find the accept-charset and enctype attribute of a form in JavaScript?
In HTML forms, the accept-charset and enctype attributes control character encoding and data transmission format. JavaScript provides properties to access these values programmatically. The accept-charset attribute specifies which character encodings the server accepts for form submission, while enctype defines how form data should be encoded when sent to the server. Using acceptCharset Property The acceptCharset property returns the value of the form's accept-charset attribute. Common values include "utf-8" (Unicode encoding) and "ISO-8859-1" (Latin alphabet encoding). Syntax document.getElementById('formID').acceptCharset; Example Here's how to retrieve the acceptable character set of a form: ...
Read MoreHow to display the date and time of a document when it is last modified in JavaScript?
In this article we are going to discuss how to display the date and time of a document when it is last modified in JavaScript. It is important to know the last updated date and time of a web document, when you read some content on the web, to know whether the web document is latest or outdated. The Document object has lastModified property which returns us the last modified date and time of a document. This is a read-only property. The value of the lastModified property is obtained by the HTTP header from the web server. ...
Read MoreHow to access an object value using variable key in JavaScript?
In this article we are going to discuss how to access an object value using variable key in JavaScript. An object value can be accessed by a Dot Notation and a Bracket Notation. To get the object value through a variable key, the value or expression inside the bracket notation must match with the existing key name, then it returns a value. The bracket notation, unlike the dot notation can be used with variables. If we are using a variable with bracket notation, the variable must reference a string. Let's understand this concept better with the help of ...
Read MoreHow to set dynamic property keys to an object in JavaScript?
Setting dynamic property keys allows you to create object properties with names that are determined at runtime. JavaScript provides three main approaches to accomplish this. Method 1: Bracket Notation The simplest way is using bracket notation to assign a value to a dynamically named property: Dynamic Property Keys - Bracket Notation Setting Dynamic Property Keys using Bracket Notation let Employee = { ...
Read MoreHow to convert a value to a number in JavaScript?
JavaScript provides several methods to convert values to numbers. Each method handles different types of input and has specific use cases. Let's explore the four main approaches: Number(), parseInt(), parseFloat(), and the unary operator (+). Using Number() Method The Number() method converts any value to a number. It's the most comprehensive conversion method and handles various data types. Convert value to number using Number() Number() Method Examples ...
Read MoreHow to convert a JSON string into a JavaScript object?
JSON (JavaScript Object Notation) is a lightweight data format commonly used for data exchange between servers and web applications. When receiving data from a server, it typically arrives as a JSON string that needs to be converted into a JavaScript object to be usable in your code. Why JSON.parse() Over eval() There are two possible ways to convert a JSON string into a JavaScript object: eval() and JSON.parse(). However, eval() is unsafe and vulnerable to code injection attacks, making it unsuitable for parsing JSON data. JSON.parse() is the recommended and secure method. Syntax JSON.parse(text[, reviver]) ...
Read MoreHow to convert JavaScript objects to primitive data types manually?
In JavaScript, objects can be converted to primitive data types (string, number, boolean) using built-in methods. This conversion is essential for operations that require primitive values rather than object references. JavaScript provides several methods for manual conversion including toString(), toDateString(), and valueOf(). Each method serves different conversion purposes and returns specific primitive types. Using the toString() Method The toString() method converts any JavaScript object to its string representation. This method is available on all objects and returns a string primitive. Syntax object.toString() Example Converting various object types to strings: ...
Read MoreAnother method other than a constructor in a JavaScript class?
JavaScript classes support multiple types of methods beyond constructors. While constructors initialize objects, other methods provide functionality and behavior to class instances. The constructor is used to create and initialize an instance of a class. However, classes can contain additional methods that perform specific operations, calculations, or return formatted data. These methods are called on class instances and have access to the object's properties through the this keyword. Types of Methods in JavaScript Classes JavaScript classes support several method types: Instance methods: Called on class instances Static methods: Called on the class itself Getter/Setter methods: ...
Read MoreGetters and setters in JavaScript classes?
In this article we are going to discuss about the getters and setters in JavaScript classes with suitable examples in JavaScript. In JavaScript, getters and setters are special methods that provide controlled access to object properties. They allow you to define custom behavior when getting or setting property values, ensuring data validation and encapsulation. Getters and setters use the get and set keywords respectively. Let's explore how to implement getters and setters in JavaScript classes and objects with practical examples. Syntax The basic syntax for getters and setters: class MyClass { ...
Read More