Onclick and Onload

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

1.

Onclick and onload


<html>
<body onload="hi()">
<script>
function hi()
{
alert("hi");
}
function hello()
{
document.write(" Button triggered");
}
</script>
<button onclick="hello()">click
here</button>
</body>

</html>
2. Onchange
<html>
<body>

<p>Select a new car from the list.</p>

<select id="mySelect" onchange="myFunction()">


<option>Audi</option>
<option>BMW</option>
<option>Mercedes</option>
<option>Volvo</option>
</select>

<p id="demo"></p>

<script>
function myFunction() {
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x;
}
</script>

</body>
</html>
3.onchange
<html>

<head>
<script type = "text/javascript">
<!--
function over() {
document.write ("Mouse Over");
}
function out() {
document.write ("Mouse Out");
}
//-->
</script>
</head>

<body>
<p>Bring your mouse inside the division to see the result:</p>
<div onmouseover = "over()" >
<h2> This is inside the division </h2>
</div>
<button onmouseout = "out()">event</button>
</body>
</html>
4. onkeypress

<html>
<body>

<input type="text" onkeypress="myFunction()">

<script>
function myFunction() {
alert("key pressed");
}
</script>

</body>
</html>
5. ondblclick

<html>
<body>

<button ondblclick="my()">double click here</button>

<script>
function my() {
document.write("hello");
}
</script>

</body>
</html>

You might also like