Sunteți pe pagina 1din 11

Javascript

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Simple JavaScript Example</title> <script type="text/javascript"> function containsblanks(s) { for(var i = 0; i < s.value.length; i++) { var c = s.value.charAt(i); if ((c == ' ') || (c == '\n') || (c == '\t')) { alert('The field must not contain whitespace'); return false; } } return true; }

</script> </head> < body> <h1>Username Form</h1> <form onSubmit="return(containsblanks(docum ent.userform.username)); " method="POST" name="userform" action="test.php"> <input type="text" name="username" size=10> <input type="submit"> </form> </body> </html>

OUTPUT IN JAVASCRIPT
<script type="text/javascript"> document.writeln("Hello, world."); </script>

POP A DIALOG BOX


<form action="test.php"> <input type="button" value="Pop a box" onclick="alert('Pop!');"> </form> <script type="text/javascript"> if (confirm("Are you sure?")) alert("Great!"); else alert("What a pity!"); </script>

FUNCTION
function count( ) { var x=1; while (x<6) { document.writeln(x + " "); x++; } }

DEBUGGING IN JAVASCRIPT
LOAD TIME RUN TIME

Events
onclick
Onfocus onload onsubmit

Methods and properties


alert( ) back( ) close( ) open( ) print( ) prompt( ) URL () write( ) and writeln( ) Submit() Value.length() Focus()

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Password Validation</title> <script type="text/javascript"> function thesame(value1, value2) { if (((value1 != null) || (value1 != "")) && value2 != "" && value1 != value2) { alert("The passwords must be identical."); return (false); } return (true); } </script>

</head> <body> <h1>Username Form</h1> <form method="post" action="test.php" name="userForm"> <br>Username: <input type="text" name="userName" size=10> <br>Password: <input type="password" name="formPassword1" size=10 onchange="thesame(document.userForm.for mPassword1.value, document.userForm.formPassword2.value);> <br>Re-enter password: <input type="password" name="formPassword2" size=10 onchange="thesame(document.userForm.for mPassword2.value, document.userForm.formPassword1.value);> <br><input type="submit" value="SUBMIT"> </form> </body> </html>

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Playing with the Browser and Windows</title> </head> <body> <h1>Playing with the Browser and Windows</h1> <form action="example.9-6.php"> <input type="button" value="Close Window" onClick="window.close( );"> <br><input type="button" value="Print Window" onClick="window.print( );"> <br><input type="button" value="Go Back" onclick="window.back( );"> <br><input type="button" value="Visit the book site" onClick="window.open('http://www.webdatabasebook.com/','BookSite', 'toolbar=yes,location=yes,menubar=yes,directories=yes,scrollbars=yes, resizable=yes');"> </form> </body> </html>

Verify()
<form action="test.php" method="post" name="custform" onsubmit="document.custform.firstname.hasNospaces = true; document.custform.firstname.description = 'First Name'; document.custform.surname.description = 'Surname'; document.custform.address.description = 'Address'; document.custform.email.description = 'Email'; document.custform.email.isEmail = true; document.custform.dob.isDate = true; document.custform.dob.description = 'Date of Birth (99/99/9999)'; document.custform.salary.description = 'Salary'; document.custform.salary.isNumeric = true; document.custform.salary.minNumber = 1; document.custform.salary.maxNumber = 1000000; document.custform.salary.hasNospaces = true; return verify(document.custform);">

S-ar putea să vă placă și