Friday, 20 April 2018
SIMPLE HTML CALCULATOR


---------------------------------------------------------------------------------------------------------------
SIMPLE HTML CALCULATOR
WHY WE NOT USE TextBox.innerHTML ?
WHEN WE USE INPUT AS A TEXTBOX WE USE VALUE IN CODE
LIKE TextBox.value
<input name="TextBox">
WHEN WE DONOT NEED FORM TAG WHEN WE USE ID INSTED OF NAME
<input id="TextBox">
---------------------------------------------------------------------------------------------------------------
<Form>
<input name="TextBox">
<Br>
<input type="Button" value=" 1 " onclick="TextBox.value += '1'" />
<input type="Button" value=" 2 " onclick="TextBox.value += '2'" />
<input type="Button" value=" 3 " onclick="TextBox.value += '3'" />
<input type="Button" value=" + " onclick="TextBox.value += '+'" />
<Br/>
<input type="Button" value=" 4 " onclick="TextBox.value += '4'" />
<input type="Button" value=" 5 " onclick="TextBox.value += '5'" />
<input type="Button" value=" 6 " onclick="TextBox.value += '6'" />
<input type="Button" value=" - " onclick="TextBox.value += '-'" />
</Br>
<input type="Button" value=" 7 " onclick="TextBox.value += '7'" />
<input type="Button" value=" 8 " onclick="TextBox.value += '8'" />
<input type="Button" value=" 9 " onclick="TextBox.value += '9'" />
<input type="Button" value=" x " onclick="TextBox.value += '*'" />
</Br>
<input type="Button" value=" c" onclick="TextBox.value = ''" />
<input type="Button" value=" 0 " onclick="TextBox.value += '0'" />
<input type="Button" value=" = " onclick="TextBox.value = eval(TextBox.value)" />
<input type="Button" value=" / " onclick="TextBox.value += '/'" />
</Br>
</Form>
---------------------------------------------------------------------------
<input id="TextBox">
<Br>
<input type="Button" value=" 1 " onclick="TextBox.value += '1'" />
<input type="Button" value=" 2 " onclick="TextBox.value += '2'" />
<input type="Button" value=" 3 " onclick="TextBox.value += '3'" />
<input type="Button" value=" + " onclick="TextBox.value += '+'" />
<Br/>
<input type="Button" value=" 4 " onclick="TextBox.value += '4'" />
<input type="Button" value=" 5 " onclick="TextBox.value += '5'" />
<input type="Button" value=" 6 " onclick="TextBox.value += '6'" />
<input type="Button" value=" - " onclick="TextBox.value += '-'" />
</Br>
<input type="Button" value=" 7 " onclick="TextBox.value += '7'" />
<input type="Button" value=" 8 " onclick="TextBox.value += '8'" />
<input type="Button" value=" 9 " onclick="TextBox.value += '9'" />
<input type="Button" value=" x " onclick="TextBox.value += '*'" />
</Br>
<input type="Button" value=" c" onclick="TextBox.value = ''" />
<input type="Button" value=" 0 " onclick="TextBox.value += '0'" />
<input type="Button" value=" = " onclick="TextBox.value = eval(TextBox.value)" />
<input type="Button" value=" / " onclick="TextBox.value += '/'" />
</Br>
---------------------------------------------------------------------------
<input id="TextBox">
<Br>
<input type="Button" value=" 1 " onclick="TextBox.value += '1'" />
<input type="Button" value=" 2 " onclick="TextBox.value += '2'" />
<input type="Button" value=" 3 " onclick="TextBox.value += '3'" />
<input type="Button" value=" + " onclick="TextBox.value += '+'" />
<Br/>
<input type="Button" value=" 4 " onclick="TextBox.value += '4'" />
<input type="Button" value=" 5 " onclick="TextBox.value += '5'" />
<input type="Button" value=" 6 " onclick="TextBox.value += '6'" />
<input type="Button" value=" - " onclick="TextBox.value += '-'" />
</Br>
<input type="Button" value=" 7 " onclick="TextBox.value += '7'" />
<input type="Button" value=" 8 " onclick="TextBox.value += '8'" />
<input type="Button" value=" 9 " onclick="TextBox.value += '9'" />
<input type="Button" value=" x " onclick="TextBox.value += '*'" />
</Br>
<input type="Button" value=" c" onclick="TextBox.value = ''" />
<input type="Button" value=" 0 " onclick="TextBox.value += '0'" />
<input type="Button" value=" = " onclick="TextBox.value = eval(TextBox.value)" />
<input type="Button" value=" / " onclick="TextBox.value += '/'" />
</Br>
Read More:
http://www.javascripthtml.com/tag/addition/
https://www.kode.to/rico08/a-simple-calculator-in-javascript-qmxyxZ
https://stackoverflow.com/questions/19578542/how-to-get-onclick-button-to-show-text-in-input-box
--------------------------------------------------------------------------------------------------------------------
SAY HELLO IN HTML
How to get onclick button to show text in input box
<!-- https://stackoverflow.com/questions/19578542/how-to-get-onclick-button-to-show-text-in-input-box -->
<!-- https://codepen.io/anon/pen/zCJcp -->
<!-- https://www.w3schools.com/jsref/event_onclick.asp -->
<!-- https://www.w3schools.com/jsref/event_onclick.asp -->
<!-- SAY HELLO IN HTML -->
The Box:<input type="text" id="thebox" value="" size=10>
<br><input type="button" value="What's in the booooox?" onclick="document.getElementById('thebox').value='head of gwyneth paltrow';">
//OR USE THIS CODE
<input type="text" id="demo">
<button onclick="document.getElementById('demo').value='HELLO'">BUTTON</button>
<button onclick="getElementById('demo').innerHTML='HELLO'">BUTTON</button>
<p id="demo"></p>
MINI CALCULATOR
----------------------------------------------------------------------------------------------------------------
<Form>
<input name="TextBox">
<input type="Button" value=" 1 " onclick="TextBox.value += '1'" />
<input type="Button" value=" + " onclick="TextBox.value += '+'" />
<input type="Button" value=" 2 " onclick="TextBox.value += '2'" />
<input type="Button" value=" = " onclick="TextBox.value = eval(TextBox.value)" />
</Form>
--------------------------------------------------------------------------
READ MORE THIS CODE NOT SHOW ERROR WHEN TYPE PLUS TWO TIMES
LIKE 1++2 =3
https://www.developerdesks.com/simple-javascript-calculator-code-with-example/1218
---------------------------------------------------------------------------
<html>
<!-- https://www.developerdesks.com/simple-javascript-calculator-code-with-example/1218 -->
<head>
</head>
<body>
<form name="calcForm">
<input type="text" name="display">
<input type="button" name="btn1" value="1"
onclick="calcForm.display.value += '1'">
<input type="button" name="btnAdd"value="+"
onclick="calcForm.display.value += ' + '">
<input type="button" name="btn2" value="2"
onclick="calcForm.display.value += '2'">
<input type="button" name="btnEqual" value="="
onclick="calcForm.display.value = eval(calcForm.display.value)">
</form>
</body>
</html>
OR USE THIS CODE:
----------------------------------------------------------------------------------------------------------------
<Form>
<input id="TextBox">
<input type="Button" value=" 1 " onclick="TextBox.value += '1'" />
<input type="Button" value=" + " onclick="TextBox.value += '+'" />
<input type="Button" value=" 2 " onclick="TextBox.value += '2'" />
<input type="Button" value=" = " onclick="TextBox.value = eval(TextBox.value)" />
</Form>
<form name="calcForm">
<input type="text" name="display">
<input type="button" name="btn1" value="1"
onclick="calcForm.display.value += '1'">
<input type="button" name="btnAdd"value="+"
onclick="calcForm.display.value += ' + '">
<input type="button" name="btn2" value="2"
onclick="calcForm.display.value += '2'">
<input type="button" name="btnEqual" value="="
onclick="calcForm.display.value = eval(calcForm.display.value)">
</form>
----------------------------------------------------------------------------------------------------------------WITHOUT FORM CODE<form name="calcForm">
<input type="text" name="display">
<input type="button" name="btn1" value="1"
onclick="calcForm.display.value += '1'">
<input type="button" name="btnAdd"value="+"
onclick="calcForm.display.value += ' + '">
<input type="button" name="btn2" value="2"
onclick="calcForm.display.value += '2'">
<input type="button" name="btnEqual" value="="
onclick="calcForm.display.value = eval(calcForm.display.value)">
</form>
----------------------------------------------------------------------------------------------------------------
<input id="TextBox">
<input type="Button" value=" 1 " onclick="TextBox.value +='1'"/>
<input type="button" value="+"
onclick="TextBox.value +=' + '"/>
<input type="Button" value=" 2 " onclick="TextBox.value += '2'" />
<input type="Button" value=" = " onclick="TextBox.value = eval(TextBox.value)" />
OR USE THIS CODE
----------------------------------------------------------------------------------------------------------------
<input type="text"id="display">
<input type="button" name="btn1" value="1"
onclick="display.value += '1'">
<input type="button" name="btnAdd"value="+"
onclick="display.value += ' + '">
<input type="button" name="btn2" value="2"
onclick="display.value += '2'">
<input type="button" name="btnEqual" value="="
onclick="display.value = eval(display.value)">
CALCULATOR WITH DOCUMENT GET ELEMENT BY ID CODE
WHEN WE USE INPUT AS A TEXTBOX WE USE VALUE IN CODE
----------------------------------------------------------------------------------------------------------------
//WHEN WE
USE INPUT AS BOX WE USE VALUE IN CODE
<input id="TextBox">
<button onclick="document.getElementById('TextBox').value+=
'1'" />1</button>
<button onclick="document.getElementById('TextBox').value+=
'+'" />+</button>
<button onclick="document.getElementById('TextBox').value+=
'2'" />2</button>
<button onclick="document.getElementById('TextBox').value =
eval(TextBox.value)" />=</button>
------------------------------------------------------------------------------------------------------------------CALCULATOR WITH INNER HTML CODE
------------------------------------------------------------------------------------------------------------------
<Button id="TextBox"></Button>
<button onclick="document.getElementById('TextBox').innerHTML+=
'1'" />1</button>
<button onclick="document.getElementById('TextBox').innerHTML+=
'+'" />+</button>
<button onclick="document.getElementById('TextBox').innerHTML+=
'2'" />2</button>
<button onclick="document.getElementById('TextBox').innerHTML
= eval(TextBox.innerHTML)" />=</button>
//OR USE THIS CODE
<Button id="TextBox"></Button>
<button onclick="TextBox.innerHTML+= '1'" />1</button>
<button onclick="TextBox.innerHTML+= '+'" />+</button>
<button onclick="TextBox.innerHTML+= '2'" />2</button>
<button onclick="TextBox.innerHTML= eval(TextBox.innerHTML)"/>=</button>
HTML CALCULATOR CHANGE INTO JAVASCRIPT CALCULATOR
FOR INPUT BOX CHANGE INNER HTML CODE INTO VALUE
----------------------------------------------------------------------------------------------------------------
<button id="Btn1">1</button>
<button id="Plus">+</button>
<button id="Btn2">2</button>
<button id="EqualBtn">=</button>
<button id="ClearBtn">Clear</button>
<div id="TextBox"></div>
<script>
Btn1.onclick = function(){
TextBox.innerHTML += "1";
};
Plus.onclick = function(){
TextBox.innerHTML += "+";
};
Btn2.onclick = function(){
TextBox.innerHTML += "2";
};
EqualBtn.onclick = function(){
TextBox.innerHTML= eval(TextBox.innerHTML)
};
ClearBtn.onclick = function(){
TextBox.innerHTML= ""
};
</script>
//FOR INPUT BOX CHANGE INNER HTML CODE INTO VALUE
<button id="Btn1">1</button>
<button id="Plus">+</button>
<button id="Btn2">2</button>
<button id="EqualBtn">=</button>
<button id="ClearBtn">Clear</button>
<input id="TextBox">
<script>
Btn1.onclick = function(){
TextBox.value += "1";
};
Plus.onclick = function(){
TextBox.value += "+";
};
Btn2.onclick = function(){
TextBox.value += "2";
};
EqualBtn.onclick = function(){
TextBox.value= eval(TextBox.value)
};
ClearBtn.onclick = function(){
TextBox.value= ""
};
</script>
Read More:
https://www.developerdesks.com/simple-javascript-calculator-code-with-example/1218
---------------------------------------------------------------------------------------------------------------
<html lang="en">
<head>
<meta charset="utf-8">
<title>Simple JavaScript
Calculator</title>
</head>
<body>
<h2>Simple JavaScript
Calculator</h2>
<form name="calcForm">
<table>
<tr>
<td colspan="4"><input type="text" name="display"
style="text-align:right"></td>
</tr>
<tr>
<td><input type="button" name="btn1" value="1"
onclick="calcForm.display.value += '1'"></td>
<td><input type="button" name="btn2" value="2"
onclick="calcForm.display.value += '2'"></td>
<td><input type="button" name="btn3" value="3"
onclick="calcForm.display.value += '3'"></td>
<td><input type="button" name="btnAdd" value="+"
onclick="calcForm.display.value += ' + '"></td>
</tr>
<tr>
<td><input type="button" name="btn4" value="4"
onclick="calcForm.display.value += '4'"></td>
<td><input type="button" name="btn5" value="5"
onclick="calcForm.display.value += '5'"></td>
<td><input type="button" name="btn6" value="6"
onclick="calcForm.display.value += '6'"></td>
<td><input type="button" name="btnSub" value="-"
onclick="calcForm.display.value += ' - '"></td>
</tr>
<tr>
<td><input type="button" name="btn7" value="7"
onclick="calcForm.display.value += '7'"></td>
<td><input type="button" name="btn8" value="8"
onclick="calcForm.display.value += '8'"></td>
<td><input type="button" name="btn9" value="9"
onclick="calcForm.display.value += '9'"></td>
<td><input type="button" name="btnMul" value="x"
onclick="calcForm.display.value += ' * '"></td>
</tr>
<tr>
<td><input type="button" name="btnClear"
value="C" onclick="calcForm.display.value = ''"></td>
<td><input type="button" name="btn0" value="0"
onclick="calcForm.display.value += '0'"></td>
<td><input type="button" name="btnEqual" value="="
onclick="calcForm.display.value = eval(calcForm.display.value)"></td>
<td><input type="button" name="btnDiv" value="/"
onclick="calcForm.display.value += ' / '"></td>
</tr>
</table>
</form>
</body>
</html>
---------------------------------------------------------------------------------------------------------------THIS CALCULATOR NOT ALLOWED TYPE OPERATOR SIGN LIKE++ OR **
READ MORE:
https://codepen.io/ckm100/pen/dPLyjZ
---------------------------------------------------------------------------------------------------------------
<!-- https://codepen.io/ckm100/pen/dPLyjZ -->
<script>
window.onload = function() {
var current,
screen,
output,
limit,
zero,
period,
operator;
screen = document.getElementById("result");
var elem = document.querySelectorAll(".num");
var len = elem.length;
for(var i = 0; i < len; i++ ) {
elem[i].addEventListener("click",function() {
num = this.value;
output = screen.innerHTML +=num;
limit = output.length;
if(limit > 16 ) {
alert("Sorry no more
input is allowed");
}
},false);
}
document.querySelector(".zero").addEventListener("click",function() {
zero = this.value;
if(screen.innerHTML === "") {
output = screen.innerHTML = zero;
}
else if(screen.innerHTML === output) {
output = screen.innerHTML +=zero;
}
},false);
document.querySelector(".period").addEventListener("click",function() {
period = this.value;
if(screen.innerHTML === "") {
output = screen.innerHTML = screen.innerHTML.concat("0.");
}
else if(screen.innerHTML === output) {
screen.innerHTML = screen.innerHTML.concat(".");
}
},false);
document.querySelector("#eqn-bg").addEventListener("click",function() {
if(screen.innerHTML === output) {
screen.innerHTML = eval(output);
}
else {
screen.innerHTML = "";
}
},false);
document.querySelector("#delete").addEventListener("click",function() {
screen.innerHTML = "";
},false);
var elem1 = document.querySelectorAll(".operator");
var len1 = elem1.length;
for(var i = 0; i < len1; i++ ) {
elem1[i].addEventListener("click",function() {
operator = this.value;
if(screen.innerHTML === "") {
screen.innerHTML = screen.innerHTML.concat("");
}
else if(output) {
screen.innerHTML = output.concat(operator);
}
},false);
}
}
</script>
<div id="background">
<div id="result"></div>
<div id="main">
<div id="first-rows">
<button class="del-bg" id="delete">Del</button>
<button value="%" class="btn-style operator opera-bg fall-back">%</button>
<button value="+" class="btn-style opera-bg value align operator">+</button>
</div>
<div class="rows">
<button value="7" class="btn-style num-bg num first-child">7</button>
<button value="8" class="btn-style num-bg num">8</button>
<button value="9" class="btn-style num-bg num">9</button>
<button value="-" class="btn-style opera-bg operator">-</button>
</div>
<div class="rows">
<button value="4" class="btn-style num-bg num first-child">4</button>
<button value="5" class="btn-style num-bg num">5</button>
<button value="6" class="btn-style num-bg num">6</button>
<button value="*" class="btn-style opera-bg operator">x</button>
</div>
<div class="rows">
<button value="1" class="btn-style num-bg num first-child">1</button>
<button value="2" class="btn-style num-bg num">2</button>
<button value="3" class="btn-style num-bg num">3</button>
<button value="/" class="btn-style opera-bg operator">/</button>
</div>
<div class="rows">
<button value="0" class="num-bg zero" id="delete">0</button>
<button value="." class="btn-style num-bg period fall-back">.</button>
<button value="=" id="eqn-bg" class="eqn align">=</button>
</div>
</div>
</div>
----------------------------------------------------------------------------------------------------------------HOW TO STOP OPERATOR SYMBOL RETYPE
LIKE ++ NOT ALLOWED
CHANGE VALUE CODE TO INNER HTML CODE
----------------------------------------------------------------------------------------------------------------
<script>
window.onload = function() {
var screen = document.getElementById("result");
var elem = document.querySelectorAll(".num");
var len = elem.length;
for(var i = 0; i < len; i++ ) {
elem[i].addEventListener("click",function() {
num = this.value;
output = screen.innerHTML +=num;
},false);
}
document.querySelector("#eqn-bg").addEventListener("click",function() {
if(screen.innerHTML === output) {
screen.innerHTML = eval(output);
}
},false);
var elem1 = document.querySelectorAll(".operator");
var len1 = elem1.length;
for(var i = 0; i < len; i++) {
elem1[i].addEventListener("click",function() {
operator = this.value;
screen.innerHTML = output.concat(operator);
},false);
}
}
</script>
<div id="result"></div>
<button value="+" class="operator">+</button>
<button value="1" class="num">1</button>
<button value="=" id="eqn-bg" class="eqn align">=</button>
------------------------------------------------------------------------------------------------------------
DIGIT BUTTON FUNTION
------------------------------------------------------------------------------------------------------------
<script>
window.onload = function() {
var screen = document.getElementById("result");
var elem = document.querySelectorAll("#num");
var len = elem.length;
for(var i = 0; i < len; i++ ) {
elem[i].addEventListener("click",function() {
num = this.value;
output = screen.innerHTML +=num;
},false);
}
}
</script>
<div id="result"></div>
<button value="1" id="num">1</button>
<button value="2" id="num">2</button>
------------------------------------------------------------------------------------------------------------
WITHOUT WINDOW FUNCTION
WITHOUT WINDOW FUNCTION
------------------------------------------------------------------------------------------------------------
<div id="result"></div>
<button value="1" class="num">1</button>
<button value="+" class="operator">+</button>
<button value="=" id="eqn-bg" class="eqn align">=</button>
<script>
var screen = document.getElementById("result");
var elem = document.querySelectorAll(".num");
var len = elem.length;
for(var i = 0; i < len; i++ ) {
elem[i].addEventListener("click",function() {
num = this.value;
output = screen.innerHTML +=num;
},false);
}
var elem1 = document.querySelectorAll(".operator");
var len1 = elem1.length;
for(var i = 0; i < len; i++)
{
elem1[i].addEventListener("click",function() {
operator =
this.value;
screen.innerHTML
= output.concat(operator);
},false);
}
document.querySelector("#eqn-bg").addEventListener("click",function() {
if(screen.innerHTML === output) {
screen.innerHTML = eval(output);
}
},false);
</script>
------------------------------------------------------------------------------------------------------------
ADD INPUT BOX BY CHANGING INNER HTML TO VALUE
ADD INPUT BOX BY CHANGING INNER HTML TO VALUE
DIFFERENT LINE IN NEXT CODE
screen.value = output.concat(operator);
<button value="+" id="num">+</button>
------------------------------------------------------------------------------------------------------------
<input id="result">
<button value="1" id="num">1</button>
<button value="+" id="operator">+</button>
<button value="=" id="eqn-bg" class="eqn align">=</button>
<script>
var screen = document.getElementById("result");
var elem = document.querySelectorAll("#num");
var len = elem.length;
for(var i = 0; i < len; i++ ) {
elem[i].addEventListener("click",function() {
num = this.value;
output = screen.value +=num;
},false);
}
var elem1 = document.querySelectorAll("#operator");
var len1 = elem1.length;
for(var i = 0; i < len; i++) {
elem1[i].addEventListener("click",function() {
operator = this.value;
screen.value = output.concat(operator);
},false);
}
document.querySelector("#eqn-bg").addEventListener("click",function() {
if(screen.value === output) {
screen.value = eval(output);
}
},false);
</script>
------------------------------------------------------------------------------------------------------------
DIGIT BUTTON FUNTION WITHOUT WINDOW FUNCTION
DIGIT BUTTON FUNTION WITHOUT WINDOW FUNCTION
<div id="result"></div>
<button value="1" id="num">1</button>
<button value="+" id="num">+</button>
<script>
var screen = document.getElementById("result");
var elem = document.querySelectorAll("#num");
var len = elem.length;
for(var i = 0; i < len; i++ ) {
elem[i].addEventListener("click",function() {
num = this.value;
output = screen.innerHTML +=num;
},false);
}
var elem1 = document.querySelectorAll("#operator");
var len1 = elem1.length;
for(var i = 0; i < len; i++) {
elem1[i].addEventListener("click",function() {
operator = this.value;
screen.value = output.concat(operator);
},false);
}
</script>
-------------------------------------------------------------------
OR CHANGE BELOW ELEM FUNCTION CODE WITH SIMPLE AS3 CODE
elem[i].addEventListener("click",FN1,false);
function FN1(){screen.value +=this.value;};
OR CHANGE BELOW ELEM FUNCTION CODE WITH SIMPLE AS2 CODE
elem[i].onclick = function(){screen.value +=this.value;};
-------------------------------------------------------------------
<input id="result">
<button value="1" id="num">1</button>
<script>
var screen = document.getElementById("result");
var elem = document.querySelectorAll("#num");
var len = elem.length;
for(var i = 0; i < len; i++ ){
elem[i].addEventListener("click",function() {
screen.value +=this.value;
},false);
}
</script>
QUERY SELECTOR ALL USE IN BUTTON
------------------------------------------------------------------------------------------------------------
<body>
<button id="Btn1">Button</button>
<p id="TEXTBOX1"></p>
<script>
var elem = document.querySelectorAll("#Btn1");
Btn1.addEventListener("click",FN1,true);
function FN1(){
TEXTBOX1.innerHTML ="Hello World"
};
</script>
</body>
//OR USE VARIABLE AS LISTENER ELEM[0]
<button id="Btn1"> BUTTON</button>
<script>
var elem = document.querySelectorAll("#Btn1");
elem[0].addEventListener("click",FN1,false)
function FN1(){
<p id="TEXTBOX1"></p>
};
</script>
----------------------------------------------------------------------------------------//AS3 BUTTON STYLE
<html>
<body>
<button id="Btn1">Button</button>
<p id="TEXTBOX1"></p>
<script>
var elem = document.querySelectorAll("#Btn1");
Btn1.addEventListener("click", function(){
TEXTBOX1.innerHTML ="Hello World"
},false);
</script>
</body>
</html>
----------------------------------------------------------------------------------------------
//AS2 BUTTON STYLE
<body>
<button id="Btn1">Button</button>
<p id="TEXTBOX1"></p>
<script>
var elem = document.querySelectorAll("#Btn1");
Btn1.onclick = function(){
TEXTBOX1.innerHTML ="Hello World"
};
</script>
</body>
--------------------------------------------------------------------------------------------------------------
DOCUMENT QUERY SELECTOR USES FOR HTML CLASSES OR ID
--------------------------------------------------------------------------------------------------------------
<button class="Btn1">Button</button>
<script>
document.querySelector(".Btn1").onclick=function(){
document.querySelector(".Btn1").innerHTML="Hello World"
};
</script>
//OR USE ID METHOD
<button id="Btn1">Button</button><script>document.querySelector("#Btn1").onclick=function(){document.querySelector("#Btn1").innerHTML="Hello
World"};</script>
--------------------------------------------------------------------------------------------------------------DIFFERENCE BETWEEN
DOCUMENT QUERY SELECTOR VS DOCUMENT GET ELEMENT ID
//DOCUMENT QUERY SELECTOR USE ID SYMBOL # OR CLASS . SYMBOL LIKE
document.querySelector("#Btn1").onclick
document.querySelector(".Btn1").onclick
//DOCUMENT QUERY ELEMENT ID NOT USE ID SYMBOL # OR CLASS . SYMBOL
document.querySelector("Btn1").onclick
document.querySelector("Btn1").onclick
<button id="Btn1">Button</button>
<script>
//DOCUMENT QUERY ELEMENT ID NOT USE ID SYMBOL # OR CLASS . SYMBOL
document.getElementById("Btn1").onclick = function(){
document.getElementById("Btn1").innerHTML ="Hello World"
};
</script>
<button id="Btn1">Button</button>
<script>
//DOCUMENT QUERY SELECTOR USE ID OR CLASS SYMBOL
document.querySelector("#Btn1").onclick = function(){
//DOCUMENT GET ELEMENT NOT USE ID OR CLASS SYMBOL
document.getElementById("Btn1").innerHTML ="Hello
World"
};
</script>
--------------------------------------------------------------------------------------------------------------SIMPLE COUNTER AS2
--------------------------------------------------------------------------------------------------------------
<button id="ButtonId">COUNTER BUTTON</button>
<div id="TextBox1">
<script>
var ZERO = 0;
TextBox1.innerHTML = ZERO;
ButtonId.onclick = function(){
ZERO = ZERO + 1;
TextBox1.innerHTML = ZERO;
if(ZERO==10){
ZERO = 0;
}
}
</script>
-----------------------------------------------------------------------------------
OR USE THIS CODE
---------------------------------------------------------------------------------
<input id="TextBoxId" value="0">
<button id="BtnId">Btn1</button>
<script>
TextBoxId.value = 0;
BtnId.onclick = function(){
TextBoxId.value = eval(TextBoxId.value) +1;
};
</script>
OR USE THIS CODE
<input id="TextBoxId" value="0">
<script>
TextBoxId.value = 0;
TextBoxId.onclick = function(){
TextBoxId.value = eval(TextBoxId.value) +1;
};
</script>
--------------------------------------------------------------------------------------------------------------
Related movie you might like to see :

SHOPIFY THEME SLIDER EDIT

INPUT BUTTON VALUE SWAP

ELEVATE ZOOM JAVA SCRIPT WITH ONE I...

QUICK FIND TOOL GOOGLE CHROME FOR ...

USE ARABIC URDU LANGUAGE IN HTML

HTML ENTITIES LIST HTML SPECIAL CHA...

MAGENTO CUSTOM BLOCK DEVOLPMENT

BUTTON PADDING CHANGE HEIGHT WIDTH

SHOPIFY FANCY BOX

BASIC ELEVATE ZOOM PLUS

ELEVATE ZOOM JAVA SCRIPT WITH ONE I...
?
+
X
Recommended for you
Loading..
Related Post for SIMPLE HTML CALCULATOR
QUICK FIND TOOL GOOGLE CHROME FOR WEB PAGE ------------------------------------------------------------------------------------------------------------------- QUICK FIND TOOL GOOGLE CHROME FOR WEB PAGE RE…
HTML ENTITIES LIST HTML SPECIAL CHARACTERS --------------------------------------------------------------------------------------------------- FIND IN GOOGLE HTML SPECIAL CHARACTERS HTML ENTITIES LIST &nb…
SIMPLE HTML CALCULATOR --------------------------------------------------------------------------------------------------------------- SIMPLE HTML CALCULATOR WHY WE NOT USE TextBox.innerHTML&n…
USE ARABIC URDU LANGUAGE IN HTML ------------------------------------------------------------------------------------------------------------- Read More: 13:22 USE ARABIC URDU LANGUAGE IN HTML&n…
HTML CODE EDITOR <form name="K"> <p style="margin-top: 0px; margin-bottom: 0px;"> <textarea name="ta1" rows="15" cols="50"> //PASTE CODE BETWEEN TEXT AREA HERE </textarea&…
ELEVATE ZOOM JAVA SCRIPT WITH ONE IMAGE -------------------------------------------------------------------------------------------------------------------------- YOU CAN CHANGE LINK <script type="text/jav…
EDIT HTML SOURCE CODE ------------------------------------------------------------------------------------------------------------------- EDIT HTML SOURCE CODE: https://www.google.co.uk/search?sourc…
CLIP BOARD EXAMPLES CODE ----------------------------------------------------------------------------------------------------------------- COPY AND PASTE BELOW CODE IN POST HTML SECTIONREAD MORE:https:…
Labels:
HTML CODE EDITOR,
HTML TUTORIALS
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.