Javascript Articles

Page 374 of 534

How to detect the browser's format for HTML input type date

Samual Sam
Samual Sam
Updated on 15-Mar-2026 451 Views

HTML input elements with type="date" always use the ISO 8601 format (YYYY-MM-DD) internally, but browsers display dates according to the user's locale settings. Here's how to work with both formats. Understanding Date Input Formats The input[type="date"] element stores values in ISO format (YYYY-MM-DD) regardless of how the browser displays it to the user. The valueAsDate property provides a JavaScript Date object for easier manipulation. Getting Current Date in ISO Format Set Current Date function setCurrentDate() { const today = new Date().toISOString().substr(0, 10); document.getElementById('dateInput').value ...

Read More

Left right subarray sum product - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 187 Views

We are required to write a JavaScript function that takes in an array of numbers of length N (N should be even) and divides the array into two sub-arrays (left and right) containing N/2 elements each, calculates the sum of each sub-array, and then multiplies both sums together. For example: If the input array is: const arr = [1, 2, 3, 4] The calculation would be: Left subarray: [1, 2] → sum = 1 + 2 = 3 Right subarray: [3, 4] → sum = 3 + 4 = 7 Product: 3 × ...

Read More

HTML5 audio not playing in PhoneGap App

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 251 Views

HTML5 audio may not play in PhoneGap (Apache Cordova) apps due to Content Security Policy restrictions or missing Android permissions. Here are the solutions to resolve audio playback issues. Content Security Policy Configuration The most common cause is a restrictive Content Security Policy. Add this meta tag to your index.html file in the section: The key part is media-src * which allows audio from any source, including local files and remote URLs. Android Permissions Setup Add the following permissions to your AndroidManifest.xml file: ...

Read More

Adjacent elements of array whose sum is closest to 0 - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 184 Views

We are required to write a JavaScript function that takes in an array of numbers and returns a subarray of two adjacent elements from the original array whose sum is closest to 0. If the length of the array is less than 2, we should return the whole array. Problem Statement For example: If the input array is − const arr = [4, 4, 12, 3, 3, 1, 5, -4, 2, 2]; Here, the sum of adjacent pair [5, -4] is 1 which is closest to 0 for any two adjacent elements of ...

Read More

Programmatically fire HTML5 dragstart after mousemove

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 201 Views

To programmatically fire an HTML5 dragstart event after a mousemove event, you need to simulate the drag behavior by creating and dispatching custom events. This approach is useful when you want to initiate dragging based on mouse movement rather than the default drag handle interaction. Basic Implementation Here's how to create a dragstart event after detecting mousemove: Drag me let isDragging = false; const draggableElement = document.getElementById('draggable'); draggableElement.addEventListener('mousedown', function(e) { isDragging = true; console.log('Mouse down - ready to drag'); ...

Read More

Middle of three elements - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 423 Views

We are required to write a JavaScript function that takes in three unsorted numbers and returns the middlemost of them using minimum number of comparisons. For example: If the numbers are − 34, 45, 12 Then our function should return the following − 34 Algorithm Explanation The algorithm uses mathematical differences to determine the middle element without explicit sorting. By calculating differences between pairs and checking their signs, we can identify the middle value efficiently. Example Following is the code − const num1 = 34; const ...

Read More

What is the most efficient way of assigning all my HTML5 video sources as trusted without having to loop over all of them

Samual Sam
Samual Sam
Updated on 15-Mar-2026 103 Views

In AngularJS applications, you can efficiently trust all HTML5 video sources by configuring the $sceDelegateProvider in your app's config phase. This eliminates the need to loop through individual video elements. Understanding SCE (Strict Contextual Escaping) AngularJS uses SCE to prevent XSS attacks by restricting resource URLs. Video sources must be explicitly trusted or whitelisted to load properly. Global Video Source Whitelisting Configure trusted video sources globally in your application module: app.config(function($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist([ // Allow same origin resource loads ...

Read More

Finding tidy numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 296 Views

A tidy number is a number whose digits are in non-decreasing order. We are required to write a JavaScript function that takes in a number and checks whether its a tidy number or not. For example: 489 is a tidy number 234557 is also a tidy number 34535 is not a tidy number Understanding Tidy Numbers In a tidy number, each digit should be less than or equal to the next digit when reading from left to right. For instance, in 234789, we have 2 ≤ 3 ≤ 4 ≤ 7 ≤ 8 ≤ ...

Read More

Detect compatibility of the new HTML5 tag with jQuery.

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 196 Views

Use the following to check the compatibility of the HTML5 tag with jQuery: Method: Testing Default Styling This method creates a element and checks if the browser applies the default yellow background color, indicating HTML5 support. function checkMarkTagSupport() { var $myEL = $(''); ...

Read More

Array of multiples - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 982 Views

We are required to write a JavaScript function that takes in two numbers, say m and n, and it returns an array of first n multiples of m. For example − If the numbers are 4 and 6 Then the output should be − const output = [4, 8, 12, 16, 20, 24] Example Following is the code − const num1 = 4; const num2 = 6; const multiples = (num1, num2) => { const res = []; for(let i = num1; i ...

Read More
Showing 3731–3740 of 5,340 articles
« Prev 1 372 373 374 375 376 534 Next »
Advertisements