You are on page 1of 11

JAVA SCRIPT EVENIMENTE

Seminar 12

<html> <head> <script type="text/javascript"> function afisare() { var r=confirm("apasa un buton"); if (r==true) { document.write("Ai apasat OK!"); } else { document.write("Ai apasat Cancel!"); } } </script> </head> <body> <input type="button" onclick=afisare()" value="Afiseaza o caseta de confirmare" /> </body> </html>

<html> <head> <script type="text/javascript"> function introducere() { var name=prompt("Introduceti numele dvs:", "Popescu ion"); if (name!=null && name!="") { document.write("Hello " + name + "! Cum te simti astazi?"); } } </script> </head> <body> <input type="button" onclick=introducere()" value="Afiseaza un prompt box" /> </body> </html>

<html> <head> <script language="javascript"> function mesaj() { alert("Buna ziua"); return 0; } function infoImagine(poza) { alert ("Apus de soare:"+"Inaltime: " +poza.height +" Latime: " +poza.width); } function maresteImagine(imagine) { imagine.height=imagine.height*1.1; imagine.width=imagine.width*1.1; } function micsoreazaImagine(imagine) { imagine.height=imagine.height/1.1; imagine.width=imagine.width/1.1; } </script> </head> <body onunload="alert('La revedere')" onload="alert('Bine ati venit')"> <h1>Exemplu evenimentul onclick</h1> <input type="button" id="unbuton" value="Apasa" onclick="mesaj()"> <h1>Exemplu evenimentul onmouseover</h1> <img src="sunset.jpg" width="300" onmouseover="infoImagine(this)"> <h1>Exemplu evenimentele onmouseover/onmouseuot</h1> <img src="sunset.jpg" width="300" onmouseover="maresteImagine(this)" onmouseout=micsoreazaImagine(this)> </body> </html>

Exemplu validare formular

<html> <head> <script language="javascript"> function valideaza_formular() { if (validare_email("email") == false || validare_parola("parola")==false) { return false; } } function validare_email(camp_formular) { var email=""; email=document.getElementById(camp_formular).value; var atPos=email.indexOf("@"); var dotPos=email.lastIndexOf("."); if (atPos<1||dotPos-atPos<2) { alert("Email incorect"); document.getElementById(camp_formular).focus; return false; } else { return true; }

function validare_parola(camp_formular) { parola = document.getElementById(camp_formular).value; if (parola.length < 6) { alert("Parola trebuie sa aiba cel putin 6 caractere"); return false; } else {return true; } } </script> </head> <body> <form action="submitpage.htm" onsubmit="return valideaza_formular();" method="post"> Email: <input type="text" name="email" size="30"/><BR /> Parola:<input type="password" name="parola" size="30"/><br /> <input type="submit" value="Submit" /> </form> </body> </html>

You might also like