Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

document.getelementbyid add number

function add(){
"use strict";
        var num1 = parseInt(document.getElementById("firstNumber").value);
        //You need to define your variable before use.
        var num2 = parseInt(document.getElementById("secondNumber").value);
        console.log(document.getElementById("firstNumber"));
        //this is a DOM object
        console.log(typeof document.getElementById("firstNumber").value);
        //this is a "string"
        console.log(typeof parseInt(document.getElementById("firstNumber").value));
        console.log(typeof +document.getElementById("firstNumber").value);
        //quickly  by use '+'
        document.getElementById("result").innerHTML =num1+num2;
}
Comment

document.getelementbyid add number

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link href="MyStyle.css" rel="stylesheet" type="text/css">

<script src="myEvents.js"> </script>
</head>

<body>

<form>
1st Number : <input type="text" id="firstNumber" /><br>
2nd Number: <input type="text" id="secondNumber" /><br>



<input type="button" onClick="add()" Value="add" />


</form>

<p>Total: 
<div id="result"> 
<input type="text"/> </div>
 Run code snippetHide results
Comment

PREVIOUS NEXT
Code Example
Javascript :: site:stackoverflow.com how to see all react dependencies 
Javascript :: discord.js profile picture 
Javascript :: ES6 reactjs problems 
Javascript :: create number format excel react native 
Javascript :: Backbone Collection Example 
Javascript :: java scrypt 
Javascript :: get user badge discordjs 
Javascript :: empty an array in javascript 
Javascript :: jsdoc default value 
Javascript :: electron npm start not working 
Javascript :: convert jquery to javascript converter online tool 
Javascript :: higher order function javascript 
Javascript :: react onsubmit get form values 
Javascript :: dictionnary js 
Javascript :: arrow expression javascript 
Javascript :: moment js remove seconds 
Javascript :: ajax post request 
Javascript :: how to add prefix to a string in javascript 
Javascript :: how to save data in javascript 
Javascript :: useThrottle 
Javascript :: javascript Adding Properties And Methods in an Object 
Javascript :: javascript Access Set Elements 
Javascript :: electron InitializeSandbox() called with multiple threads in process gpu-process. 
Javascript :: cntl intellisense tailwind 
Javascript :: circular object array 
Javascript :: how to get html element coords in js 
Javascript :: phaser random ellipse 
Javascript :: regular expression a-z and 0-9 
Javascript :: JS table with rows that have alternating colours 
Javascript :: getauth firebase admin node.js 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =