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
Web Development Articles
Page 75 of 801
Check whether Enter key is pressed or not and display the result in console with JavaScript?
For this, use onkeypress. Let’s first create input text −Now, let’s see the demoForEnterKey() function and check whether enter key is pressed or not −function demoForEnterKey(eventName) { if (eventName.keyCode == 13) { var t = document.getElementById("textBox"); console.log(t.value); console.log("Enter key is pressed.....") return true; } else { console.log("Enter key is not pressed.....") return false; } }Example Document function demoForEnterKey(eventName) { if (eventName.keyCode == 13) { ...
Read MoreIs it possible to select text boxes with JavaScript?
Yes, select text box with JavaScript using the select() method. At first, let us create an input text −Enter your Name: Select Text BoxNow, let us select the text box on button click −Example Document Enter your Name: Select Text Box function check(){ document.getElementById("txtName").select(); } To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −When you click the ...
Read MoreJavaScript (+) sign concatenates instead of giving sum?
The + sign concatenates because you haven’t used parseInt(). The values from the textbox are string values, therefore you need to use parseInt() to parse the value.After selecting the value from text box, you need to parse that value. Following is the code −Example Document FirstNumber: SecondNumber: function sumOfTwoNumbers(){ var num1 = document.querySelector(".num1").value; var num2 = document.querySelector(".num2").value; var addition = parseInt(num1)+parseInt(num2); document.querySelector(".output").innerHTML = "The addition of two numbers= " + addition; ...
Read MoreHow to create an image of matrix of pixels in R?
A matrix can be converted into a pixel’s image of matrix. It is defined as the area of the matrix which contains pixels with equal or different sizes of left, right, bottom and upper.We can create this by using image function and its argument useRaster with the matrix data.Example> M par(mar=c(5,5,5,5)) > image(M,useRaster=TRUE,axes=FALSE)Output> par(mar=c(10,10,10,10)) > image(M,useRaster=TRUE,axes=FALSE)Output> par(mar=c(2,2,2,2)) > image(M,useRaster=TRUE,axes=FALSE)OutputPixel matrix with grey color −> image(M,axes=FALSE,col=grey(seq(0,1,length=180)))Output
Read MoreSelect all elements with “data-” attribute with jQuery and display on Console?
To select all elements with “data-“ attribute, use document.querySelectorAll(“”). Following is the code −Example Document var result=document.querySelectorAll('[data-sentence]'); for (var index in result){ if (result.hasOwnProperty(index)){ console.log(result[index].getAttribute('data-sentence')); } } To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −
Read MoreGet value of any attribute from XML data in JavaScript?
To get value of any attribute from XML data, use attr() in JavaScript. Following is the code −Example Document var yourXMLDetails = '' +'' +'' +'' console.log("Game Details==="+$(yourXMLDetails).attr("details")); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −
Read MoreHow to set div position relative to another div in JavaScript?
For this, you need to use “flex-direction” concept of CSS. Let’s say the following is our CSS style − .demo{ display: flex; flex-direction: column-reverse; } Now, set the div position relative to another div −Example Document .demo{ display: flex; flex-direction: column-reverse; } DIV_DEMO1 DIV_DEMO2 To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −
Read MoreCreate global variable in jQuery outside document.ready function?
To create a global variable, you need to place variable inside the tag. Following is the code −Example Document checkGlobalVariable var globalVariable; $(document).ready(function() { function initializeGlobalVariable() { globalVariable = [{ "name":"John", "age":23 }]; } initializeGlobalVariable(); }); function createGlobalVariable() { if (globalVariable.length) { console.log('The Global variable name ...
Read MoreCalling asynchronous code from index.html page in JavaScript?
You need to use async and await with body onLoad attribute Following is the code −index.htmlExample Document async function callFunction(){ await testFunction(); } function testFunction(){ console.log("Hi..."); } To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −
Read MoreCheck if input is a number or letter in JavaScript?
To check if the input is a number or letter, use the isNaN() function from JavaScript. It returns true if the value is NaN i.e. Not a Number. Following is the code −Example Document Enter the value: function checkInputIsNumber(){ var value=document.forms["checkingInput"]["txtValue"].value; if (isNaN(value)){ alert("Please Provide the input as a number"); return false; } } To run the above program, save the file name ...
Read More