JavaScript DHTML/Form Control/Password — различия между версиями

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

Версия 09:59, 26 мая 2010

Demonstrates password field and hiden field

  
<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>



Get text input max Length

 
    
<html>
<body>
<input type="password" id="myText">
<script language="JavaScript">
    document.getElementById("myText").maxLength = 10;
</script>
</body>
</html>



Methods and Properties of the Password Object

 
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.



Password field size

 
    
<html>
<body>
<input id="yourPass" type="password">
<script language="JavaScript">
    document.getElementById("yourPass").size = 8;
</script>
</body>
</html>



Password Protecting a Page

 
<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>