JavaScript DHTML/Form Control/Form Reset

Материал из Web эксперт
Версия от 07:21, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

form.reset() and form.submit() Methods

   
<html> 
<head> 
<title>Registration Form</title> 
</head> 
<body> 
<form name="entries" method="POST" action=""> 
Enter your first name:<input type="text" name="firstName" id="firstName" /> 
<p>Enter your last name:<input type="text" name="lastName" id="lastName" /></p> 
<p>Enter your address:<input type="text" name="address" id="address" /></p> 
<p>Enter your city:<input type="text" name="city" id="city" /></p> 
<p><input type="radio" name="gender" id="gender1" checked="checked"/>Male 
<input type="radio" name="gender" id="gender2" />Female</p> 
<p><input type="checkbox" name="retired" id="retired" />I am retired</p> 
</form> 
<p><a href="javascript:document.forms[0].submit()">
  <img alt="image" src="submit.jpg" height="25" width="100" border="0" /></a> 
  <a href="javascript:document.forms[0].reset()">
  <img alt="image" src="reset.jpg" height="25" width="100" border="0" /></a></p> 
</body> 
</html>



Reset the fields in a form

  
<html>
<head>
<script type="text/javascript">
function formReset(){
    var x=document.forms.myForm
    x.reset()
}
</script>
</head>
<body>
<form name="myForm">
<p>Enter some text in the text fields and then press the "Reset form" button</p>
<input type="text" size="20"><br>
<input type="text" size="20"><br>
<br>
<input type="button" onclick="formReset()" value="Reset form">
</form>
</body>
</html>



The onreset and onsubmit Event Handlers

   
<html> 
<head> 
<title>Submit and Reset Confirmation</title> 
<script type="text/javascript"> 
function allowReset() { 
    return window.confirm("Go ahead and clear the form?"); 
} 
function allowSend() { 
    return window.confirm("Go ahead and mail this info?"); 
} 
</script> 
</head> 
<body> 
<form method="POST" enctype="text/plain" action="mailto:a@b.ru" onreset="return allowReset()" onsubmit="return allowSend()"> 
Enter your first name:
<input type="text" name="firstName" id="firstName"/> 
Enter your last name:
<input type="text" name="lastName" id="lastName"/>
Enter your address:
<input type="text" name="address" id="address"/>
Enter your city:
<input type="text" name="city" id="city" />
<input type="radio" name="gender" id="gender1" checked="checked" />
Male 
<input type="radio" name="gender" id="gender2" />Female
<input type="checkbox" name="retired" id="retired" />I am retired
<input type="reset" /> 
<input type="submit" />
</form> 
</body> 
</html>