0% found this document useful (0 votes)
37 views

ASFWEB

This document contains two HTML code examples using JavaScript event handlers and functions. The first example uses an onchange event handler to calculate the square and cube of a number entered in a form. The second example uses a prompt to get a number input, calls a factorial function, and displays the result.

Uploaded by

Vimala Rasu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

ASFWEB

This document contains two HTML code examples using JavaScript event handlers and functions. The first example uses an onchange event handler to calculate the square and cube of a number entered in a form. The second example uses a prompt to get a number input, calls a factorial function, and displays the result.

Uploaded by

Vimala Rasu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

HTML WITH EVENTHANDLER

<html> <head> <script language="javascript"> function calc(form) { form.square.value=form.entry.value*form.entry.value form.cube.value=form.entry.value*form.entry.value*form.entry.value } </script> </head> <body onload="var name=prompt("enter your name",'name');alert("hi!"+name);"> <form method=post> enter a number:<input type="text" name="entry" value="" onchange="calc(this.form);"> <br> square of number entered:<input type="text" name="square" value="" onfocus="this.blur();"> <br> cube of number entered:<input type="text" name="cube" value="" onfocus="this.blur();"> </form> </body> </html>

HTML WITH JAVASCRIPT <html> <head> <script language="javascript"> function factorial(num) { var fact=1; if(num>1) { for(i=1;i<=num;i++) fact=fact*i; return fact } else { return fact; } } </script> </head> <body> <script> var input=prompt("enter a number","1"); var output=factorial(input); document.write("the factorial of"+input+"is"+output); </script> </body> </html>

You might also like