1<!DOCTYPE html>
2<html>
3 <head>
4 <title>Title of the document</title>
5 </head>
6 <body>
7 <p>There is a hidden message for you. Click to see it.</p>
8 <button onclick="myFunction()">Click me!</button>
9 <p id="demo"></p>
10 <script>
11 function myFunction() {
12 document.getElementById("demo").innerHTML = "Hello Dear Visitor!</br> We are happy that you've chosen our website to learn programming languages. We're sure you'll become one of the best programmers in your country. Good luck to you!";
13 }
14 </script>
15 </body>
16</html>
1 <input type="text" name="text" id="test" onmouseover="skriv('klick')">
2 <input type="button" name="send" value="Skicka" id="klick" onclick="skriv('test')">
3
4
5 <script src="lib/script.js"></script>
6
7
8// in lib/script.js
9
10 function skriv(name) {
11 document.getElementById(name).style.backgroundColor='red';
12 }
1import java.awt.*;// import functions
2import java.awt.event.*;
3
4public class buttonevent extends Frame implements ActionListener {
5 int num;
6 Button b1;
7 TextField t1;
8
9 public buttonevent() {//constructor
10 setLayout(new FlowLayout());
11
12 b1 = new Button("click me");//button named "click me" is created.
13 t1 = new TextField(20);
14
15 add(b1);//that button is added to the frame by add function.
16 add(t1);
17
18 b1.addActionListener(this);
19
20 }
21
22 public void actionPerformed(ActionEvent ae) {//event function
23 String cmd = ae.getActionCommand();
24 if (num == 0) {
25 System.out.println(cmd);
26 }
27 if (cmd.equals("click me")) {
28 num++;
29 }
30 if ((num % 2) != 0) {
31 t1.setText("Hello Buddy!");
32 }
33 if ((num % 2) == 0) {
34 t1.setText(" ");
35 System.out.println(num);
36 }
37 }
38
39 public static void main(String args[]) {//main function
40 buttonevent ob = new buttonevent();
41 ob.setSize(500, 500);
42 ob.setVisible(true);
43 ob.setTitle("button Event Handling");
44 }
45}