JavaScript DHTML/Form Control/Password

Материал из Web эксперт
Перейти к: навигация, поиск

Demonstrates password field and hiden field

   <source lang="html4strict">
 

<html> <head> <title>Password</title> <script> function checkPass(){

 var guess = document.myForm.pwdField.value;
 var secret = document.myForm.hiddenField.value;
 if (guess == secret){
   document.myForm.txtOutput.value = "correct";
 } else {
   document.myForm.txtOutput.value = "incorrect.";
 }

}</script> </head> <body> <form name = myForm> Please enter password</td> <input type = "password" name = pwdField> <input type = "button" value = "click me" onClick = "checkPass()"> <textArea name = "txtOutput" rows = 1 cols = 35></textarea> <input type = "hidden" name = "hiddenField" value = "JavaScript"> </form> </body> </html>


 </source>
   
  


Get text input max Length

   <source lang="html4strict">

   

<html> <body> <input type="password" id="myText"> <script language="JavaScript">

   document.getElementById("myText").maxLength = 10;

</script> </body> </html>


 </source>
   
  


Methods and Properties of the Password Object

   <source lang="html4strict">

Method blur() Removes focus from the password box. focus() Sets focus to the password box. handleEvent() Invokes the default handler for the specified event. select() Selects the text entered in the password box. Property defaultValue Refers to the value attribute of the HTML password box. form Refers to the form that contains the password box. name Refers to the name attribute of the HTML password box. type Refers to the type attribute of the HTML password box. value Refers to the current contents of the password box.


 </source>
   
  


Password field size

   <source lang="html4strict">

   

<html> <body> <input id="yourPass" type="password"> <script language="JavaScript">

   document.getElementById("yourPass").size = 8;

</script> </body> </html>


 </source>
   
  


Password Protecting a Page

   <source lang="html4strict">

<HTML> <HEAD> <TITLE> Test that password </TITLE> </HEAD> <BODY> <SCRIPT> var password = ""; password=prompt("Please enter your password!",""); if (password != null) {

  location.href= "http://www.wbex.ru"; 

} </SCRIPT> </BODY> </HTML>


 </source>