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
Javascript Articles
Page 411 of 534
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 MoreWhat is the use of ()(parenthesis) brackets in accessing a function in JavaScript?
The parentheses () are crucial for function invocation in JavaScript. Accessing a function without parentheses returns the function reference, while using parentheses calls the function and returns its result. Function Reference vs Function Call When you write a function name without parentheses, JavaScript treats it as a reference to the function object. With parentheses, JavaScript executes the function. Without Parentheses - Function Reference Accessing a function without parentheses returns the function definition itself, not the result: function toCelsius(f) { return (5/9) * ...
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 MoreHow to access 'this' keyword inside an arrow function in JavaScript?
The JavaScript 'this' keyword refers to the object it belongs to. Arrow functions handle 'this' differently than regular functions - they inherit 'this' from their surrounding scope rather than creating their own. How Arrow Functions Handle 'this' Arrow functions don't have their own 'this' binding. Instead, they capture the 'this' value from the enclosing lexical scope at the time they are defined. function Student(fname, grade) { this.fname = fname; this.grade = grade; this.details = function() { ...
Read More