Css Practical 7 and 8

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

COMPUTER ENGINEERING DEPARTMENT

Subject: Client Side Scripting Subject Code: 22519


Semester: 5th Course: Computer Engineering
Laboratory No: L001A Name of Subject Teacher:
Name of Student: Roll Id: 17202C0009

Experiment No: 7
Title of Experiment Create a webpage to Implement Form Event part.

Theory:

What is an Event ?
JavaScript's interaction with HTML is handled through events that occur when the user or the
browser manipulates a page.

When the page loads, it is called an event. When the user clicks a button, that click too is an
event. Other examples include events like pressing any key, closing a window, resizing a
window, etc.

Developers can use these events to execute JavaScript coded responses, which cause buttons
to close windows, messages to be displayed to users, data to be validated, and virtually any
other type of response imaginable.

The standard HTML 5 events are listed here for your reference. Here script indicates a
Javascript function to be executed against that event.

Attribute Valu Description


e
Offline script Triggers when the document goes offline
Onabort script Triggers on an abort event
onafterprint script Triggers after the document is printed
onbeforeonload script Triggers before the document loads
onbeforeprint script Triggers before the document is printed
onblur script Triggers when the window loses focus
oncanplay script Triggers when media can start play, but might has to stop for buffering
oncanplaythrough script Triggers when media can be played to the end, without stopping for
buffering
onchange script Triggers when an element changes
onclick script Triggers on a mouse click
oncontextmenu script Triggers when a context menu is triggered
ondblclick script Triggers on a mouse double-click

Page | 1
ondrag script Triggers when an element is dragged
ondragend script Triggers at the end of a drag operation
ondragenter script Triggers when an element has been dragged to a valid drop target
ondragleave script Triggers when an element is being dragged over a valid drop target
ondragover script Triggers at the start of a drag operation
ondragstart script Triggers at the start of a drag operation
ondrop script Triggers when dragged element is being dropped
ondurationchange script Triggers when the length of the media is changed
onemptied script Triggers when a media resource element suddenly becomes empty.
onended script Triggers when media has reach the end
onerror script Triggers when an error occur
onfocus script Triggers when the window gets focus
onformchange script Triggers when a form changes
onforminput script Triggers when a form gets user input
onhaschange script Triggers when the document has change
oninput script Triggers when an element gets user input
oninvalid script Triggers when an element is invalid
onkeydown script Triggers when a key is pressed
onkeypress script Triggers when a key is pressed and released
onkeyup script Triggers when a key is released
onload script Triggers when the document loads
onloadeddata script Triggers when media data is loaded
onloadedmetadata script Triggers when the duration and other media data of a media element is
loaded
onloadstart script Triggers when the browser starts to load the media data
onmessage script Triggers when the message is triggered
onmousedown script Triggers when a mouse button is pressed
onmousemove script Triggers when the mouse pointer moves
onmouseout script Triggers when the mouse pointer moves out of an element
onmouseover script Triggers when the mouse pointer moves over an element
onmouseup script Triggers when a mouse button is released
onmousewheel script Triggers when the mouse wheel is being rotated
onoffline script Triggers when the document goes offline
onoine script Triggers when the document comes online
ononline script Triggers when the document comes online
onpagehide script Triggers when the window is hidden
onpageshow script Triggers when the window becomes visible
onpause script Triggers when media data is paused
onplay script Triggers when media data is going to start playing
onplaying script Triggers when media data has start playing
onpopstate script Triggers when the window's history changes
onprogress script Triggers when the browser is fetching the media data
onratechange script Triggers when the media data's playing rate has changed
onreadystatechang script Triggers when the ready-state changes
e
onredo script Triggers when the document performs a redo
onresize script Triggers when the window is resized
onscroll script Triggers when an element's scrollbar is being scrolled
onseeked script Triggers when a media element's seeking attribute is no longer true,
and the seeking has ended
onseeking script Triggers when a media element's seeking attribute is true, and the
seeking has begun
onselect script Triggers when an element is selected

Page | 2
onstalled script Triggers when there is an error in fetching media data
onstorage script Triggers when a document loads
onsubmit script Triggers when a form is submitted
onsuspend script Triggers when the browser has been fetching media data, but stopped
before the entire media file was fetched
ontimeupdate script Triggers when media changes its playing position
onundo script Triggers when a document performs an undo
onunload script Triggers when the user leaves the document
onvolumechange script Triggers when media changes the volume, also when volume is set to
"mute"
onwaiting script Triggers when media has stopped playing, but is expected to resume

Program:-

7.3

<html>

<head>

<title>key event</title>

</head>

<body>

<div id ="panel"></div>

<script>

var panel;

panel =document.getElementById("panel");

panel.innerHTML="Press a Key.....";

document.addEventListener("keydown",keydown,false);

document.addEventListener("keyup",keyup,false);

document.addEventListener("keypress",keypress,false);

function keydown()

panel.innerHTML+="</br>keypressed:";

function keyup()

Page | 3
panel.innerHTML+="</br>keyreleased:";

}function keypress(e)

var keynum =(window.event)?event.keycode:e.which;

panel.innerHTML+=string.fromCharCode(keynum);

</script>

</body>

</html>

Output:-

7.4

<html>

<body>

<div id="panel"></div>

<script>

function clickResponse()

Page | 4
{

this.innerHTML+="click detected <hr>";

function doubleclickResponse()

this.innerHTML+="Double click detected ";

function mousedownResponse()

this.innerHTML+="<br> mouse button down <br> ";

function mouseupresponse()

this.innerHTML+="<br> mouse button up <br> ";

function init()

var panel = document.getElementById("panel");

panel.innerHTML = "click here <br>";

panel.onclick = clickResponse ;

panel.ondblclick = doubleclickResponse ;

panel.onmouseup = mouseupresponse;

panel.onmousedown = mousedownResponse;

document.addEventListener("DOMcontentLoaded",init(),false);

</script>

</body>

Page | 5
</html>

Output:-

7.5

<html>

<head>

<script>

function compute()

Page | 6
var a=document.getElementById("txt1").value;

var b=document.getElementById("txt2").value;

var c=parseInt(a)+parseInt(b);

document.getElementById("txt3").value=c;

</script>

</head>

<body>

Enter value of A:<input type="text" id="txt1"/><br/>

Enter value of B:<input type="text" id="txt2"/><br/>

Sum:<input type="text" id="txt3"/><br/>

<button id="btn1" type="button" onClick="compute()"> Addition</button>

<script type ="text/ javascript">

var button=window.document.getElementById("btn1");

button.addEventListner("click",compute(),false);

</script>

</body>

</html>

Output:-

Page | 7
7.6

<html>

<head>

<title>EventHello.html</title>

<script type="text/javascript" src="EventHello.js">

</script>

<meta http-equiv="Content-Script-Type" content="text/javascript" />

<script>

function sayHello(event)

window.alert("Hello World!\n\n" +

"Event type: " + event.type + "\n" +

"Event target element type: " + event.target.nodeName);

return;

</script>

</head>

Page | 8
<body>

<p>

<button id="myBtn" type="button">Click for a message!</button>

<script type="text/javascript">

var button = window.document.getElementById("myBtn");

button.addEventListener("click", sayHello, false);

</script>

</p>

</body>

</html>

Output:-

7.7

Page | 9
<html>

<body>

<div id="panel"></div>

<script>

var panel,flag;

panel=document.getElementById("panel");

flag=true;

panel.innerHTML="move the mouse..";

document.onmousemove=mousemove;

panel.onmouseover=mouseover;

panel.onmouseout=mouseout;

var panel,flag;

function mousemove(e)

if(flag)

panel.innerHTML="mouse is at X"+e.x+",Y:"+e.y;

function mouseover()

flag=false;

panel.innerHTML="mouse is over";

function mouseout()

Page | 10
flag=true;

</script>

</body>

</html>

Output:-

7.8

<!DOCTYPE html>

<html>

<body>

<p>A function is triggered when the user is pressing a key in the input field.</p>

value 1 <input type="text" onkeypress="myFunction1()">

</br>

value 2 <input type="text" onkeydown="myFunction2()">

</br>

name: <input type="text" id="fname" onkeyup="myFunction3()">

Page | 11
<script>

function myFunction1() {

alert("You pressed a key inside the input field");

function myFunction2()

alert("key down");

function myFunction3() {

var x = document.getElementById("fname");

x.value = x.value.toUpperCase();

</script>

</body>

</html>

Output:-

Page | 12
Grade and P1 (35M) P2 (15M) Total ( 50 M) Dated Sign
Dated
Signature of
Teacher

Page | 13

You might also like