Web Development Articles

Page 75 of 801

Check whether Enter key is pressed or not and display the result in console with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 361 Views

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 More

Is it possible to select text boxes with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 779 Views

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 More

JavaScript (+) sign concatenates instead of giving sum?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 6K+ Views

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 More

How to create an image of matrix of pixels in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

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 More

Select all elements with “data-” attribute with jQuery and display on Console?

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

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 More

Get value of any attribute from XML data in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

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 More

How to set div position relative to another div in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 754 Views

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 More

Create global variable in jQuery outside document.ready function?

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

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 More

Calling asynchronous code from index.html page in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 311 Views

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 More

Check if input is a number or letter in JavaScript?

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

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
Showing 741–750 of 8,006 articles
« Prev 1 73 74 75 76 77 801 Next »
Advertisements