Event Listener

You might also like

You are on page 1of 6

EVENT LISTENER

<!-- <!DOCTYPE html>


<html>
<body>

<button id="myBtn">Try it</button>

<script>
document.getElementById("myBtn").addEventListener("
dblclick",function()
{
alert('hey there');
});
</script>
</body>
</html>

INKREMENTO NUMRIN ME DY SA HERE KLIKOHET


BUTONI
<html>
<body>
<p><input id = "butoniInkremento" type = "button"
value = "inkremento">
<p>Numero = <span id = "numero">0</span></p>
<script>
var numeruesi=0;
var intervali;
function start(){

document.getElementById("butoniInkremento").addEve
ntListener("click",inkremento,false);}
function inkremento() {
numeruesi+=2;
document.getElementById("numero").innerHTML=
numeruesi; }
window.addEventListener( "load", start, false );

</script>
</body>
VOLUMI SFERES
<html>
<body>
<label>Rrezja</label>
<input type="number" id="rrezja"/>
<button id="volumi"> Volumi </button>
<script>
function start(){
document.getElementById("volumi").addEventListener(
"click",calculate,false);}
function calculate(){
var rrezja=document.getElementById("rrezja").value;
var rrezja=parseInt(rrezja);
var volumi=( 4.0 / 3.0 ) * Math.PI *
Math.pow( rrezja, 3 );
alert("Volumi i sferes eshte"+volumi); }
window.addEventListener( "load", start, false );
</script> </body> </html>

Write a script that uses a form to get the radius of a


circle from the user, then calls the function
circleArea to calculate the area of the circle and display
the result in a paragraph on the page.
To get the number from the form, use the techniques
shown in Self-Review Exercise 9.6.
<html>
<body> <form>
<label> Rrezja </label>
<input type="number" id="rrezja"/>
<button id="siperfaqja"> Siperfaqja </button>
</form>
<script>
window.addEventListener("load",start,false);
function start(){
document.getElementById("siperfaqja").addEventListen
er("click",siperfaqja,false); }
function siperfaqja(){
var rrezja=document.getElementById("rrezja").value;
var rrezja=parseInt(rrezja);
var siperfaqja=Math.PI*rrezja*rrezja;
alert("Siperfaqja eshte: "+siperfaqja); }
</script> </body> </html>
A parking garage charges a $2.00 minimum fee to park
for up to three hours. The garage
charges an additional $0.50 per hour for each hour or
part thereof in excess of three hours. The maximum
charge for any given 24-hour period is $10.00. Assume
that no car parks for longer than 24
hours at a time. Write a script that calculates and
displays the parking charges for each customer
who parked a car in this garage yesterday. You should
use a form to input from the user the hours
parked for each customer. The program should display
the charge for the current customer and
should calculate and display the running total of
yesterday’s receipts. The program should use the
function calculateCharges to determine the charge for
each customer. To get the number from the
form, use the techniques shown in Self-Review
Exercise 9.6.

<html>
<body>
<label> Ore ne garazh </label>
<input type="number" id="ore"/>
<button id="pagesa"> Pagesa</button>
<p id="rezultati"> </p>
<p id="totali"> </p>
<script>
window.addEventListener("load",start,false);
function start(){
document.getElementById("pagesa").addEventListener(
"click",llogarit,false); }
function llogarit(){
var ore=document.getElementById("ore").value;
var ore=parseInt(ore);
var shuma=0;
var totali=0;
while(ore!==-1){
if (ore<=3) {
shuma=2;
totali=totali+shuma;
} else if (ore>24) {
shuma=10;
totali=totali+shuma;
} else {
shuma=2+(ore-3)*0.5;
totali=totali+shuma;
}…vazhdon me poshte
document.getElementById("rezultati").innerHTML =
"Klienti ka paguar:"+shuma;
document.getElementById("totali").innerHTML =
"Totali eshte:"+totali;
ore=document.getElementById("ore").value;
}}
</script> </body> </html>

Write a function integerPower( base, exponent ) that


returns the value of
base exponent
For example, integerPower( 3, 4 ) = 3 * 3 * 3 * 3.
Assume that exponent and base are integers.
Function integerPower should use a for or while
statement to control the calculation. Incorporate
this function into a script that reads integer values
from an HTML5 form for base and exponent
and performs the calculation with the integerPower
function. The HTML5 form should consist
of two text fields and a button to initiate the
calculation. The user should interact with the program
by typing numbers in both text fields, then clicking the
button.
<html>
<body>
<label>Baza</label>
<input type="number" id="baza"/>
<label>Eksponenti</label>
<input type="number" id="eksponenti"/>
<button id="rezultati"> Llogarit </button>
<p id="final"><p>

<script>

window.addEventListener("load",start,false);
function start() {
document.getElementById("rezultati").
addEventListener("click",integerPower,false);
}
function integerPower(){
var baza=document.getElementById("baza").value;
var baza=parseInt(baza);
var eksponenti=document.getElementById
("eksponenti").value;
var eksponenti=parseInt(eksponenti);
var rezultati=1;
for(var i=1;i<=eksponenti;i++){
rezultati=rezultati*baza;
}

document.getElementById("final").innerHTML
="Rezultati eshte:"+rezultati;
}
</script>
</body>
</html>

Write a function multiple that determines, for a pair of


integers, whether the second integer
is a multiple of the first. The function should take two
integer arguments and return true if the
second is a multiple of the first, and false otherwise.
Incorporate this function into a script that
inputs a series of pairs of integers (one pair at a time).
The HTML5 form should consist of two text
fields and a button to initiate the calculation. The user
should
<html>
<body>
<label> Numri i pare </label>
<input type="number" id="pari"/>
<label> Numri i dyte </label>
<input type="number" id="dyti"/>
<button id="gjej"> Gjej </button>
<p id="rezultati"></p>

<script>
window.addEventListener("load",start,false);
function start(){
document.getElementById("gjej").addEventListener
("click",multiple,false); }

function multiple(){
var ipari=parseInt(document.getElementById
("pari").value);
var idyti=parseInt(document.getElementById
("dyti").value);
if (idyti%ipari==0){
document.getElementById("rezultati").innerHTML=true;
} else {
document.getElementById("rezultati").innerHTML=false
;} }
</script>

</body>
</html>

You might also like