JavaScript Tutorial/Form/Reset

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

Reset

The Reset object represents a Reset button within an HTML form.

The button is created using the HTML <input> tag and specifying the TYPE attribute as reset.

Reset buttons are used for form submissions.

Property/Method Description blur() Removes focus from Reset button click() Simulates a mouse click on a Reset button focus() Sets the focus to the Reset button form Specifies the form name that contains the Reset button handleEvent() Invokes the event handler name HTML NAME attribute for the Reset button onBlur Event handler for Blur event onClick Event handler for Click event onFocus Event handler for Focus event type HTML TYPE attribute for the Reset button value HTML VALUE attribute for the Reset button



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset object</title>
   </head>
   <body>
   <form name="form1">
   Click the Reset button to reset the form.
   


Enter Name: <input type="text" Name="name" Size=15>
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset>

</form> </body> </html></source>

Reset.blur()

The blur() method removes the focus from the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset blur method</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>
<input type="reset" name=resetbutton value=Reset onBlur="showMsg()">

</form> </body> </html></source>

Reset.click()

The click method simulates a mouse click on the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset click method</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset onClick="inform()">

<input type="button" value="Simulate Click" onClick="clickReset()"> </form> </body> </html></source>

Reset.focus()

The focus() method sets the focus to the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset focus method</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset>

<input type="button" value="Set Focus to Reset" onClick="focusReset()">
</form> </body> </html></source>

Reset.form

The form property obtains the name of the form that contains the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset form property</title>
   </head>
   <body>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset onClick="alert("The form name is: " + document.form1.resetbutton.form.name)">

</form> </body> </html></source>

Reset.handleEvent()

Syntax



   <source lang="javascript">

reset.handleEvent(event)</source>


Reset.name

The name property represents the name given to a Reset button as specified from the NAME attribute of the HTML <input type="reset"> tag.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset name property</title>
   </head>
   <body>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset onClick="alert("The reset button name is: " + ?document.form1.resetbutton.name)">

</form> </body> </html></source>

Reset.onBlur

The onBlur event handler is an event handler that specifies when the focus has been removed from the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset onBlur event handler</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   <form name="form1">
   Click the reset button and then click in a text area.
   

Enter Name: <input type="text" Name="name" Size=15>
Enter Phone: <input type="text" Name="phone" Size=10> <input type="reset" name=resetbutton value=Reset onBlur="setMsg()">
</form> </body> </html></source>

Reset.onClick

The onClick property is an event handler used to handle the event of a mouse click on the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset onClick event handler</title>
   </head>
   <body>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset onClick="alert("The reset button was clicked")">

</form> </body> </html></source>

Reset.onFocus

The onFocus event handler is used to specify when the focus is set on the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset onFocus event handler</title>
   </head>
   <body>
   <script language="JavaScript">
   
   </script>
   <form name="form1">
   Click the reset button.
   

Enter Name: <input type="text" Name="name" Size=15>
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset onFocus="setMsg()">
</form> </body> </html></source>

Resetting a form on page load

   <source lang="javascript">

<html> <head> <title>Resetting a form on page load</title> <script type="text/javascript" language="javascript">

</script> </head> <body onload="ClearForm()">

<form name="MyForm" action="http://www.wbex.ru/" method="Post">
First Name: <input type="text" name="FirstName"/>
Last Name: <input type="text" name="LastName"/>
User Number: <input type="text" name="UserNo"/>
  <input type="submit" value="Submit Form"/>

</form> </body> </html></source>


Reset.type

The type property represents the HTML TYPE attribute of the Reset button.

In the case of a Reset button, this will always be reset.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset type property</title>
   </head>
   <body>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset onClick="alert("The button type is: " + document.form1.resetbutton.type)">

</form> </body> </html></source>

Reset.value

The value property represents the HTML VALUE attribute of the Reset button.



   <source lang="javascript">

<html>

   <head>
   <title> Example of the reset value property</title>
   </head>
   <body>
   <form name="form1">
   Enter Name: <input type="text" Name="name" Size=15>
   
Enter Phone: <input type="text" Name="phone" Size=10>

<input type="reset" name=resetbutton value=Reset onClick="alert("The button value is: " + document.form1.resetbutton.value)">

</form> </body> </html></source>