Fire-House 58

Event Handlers

onSubmit
onReset

e-8


JavaScript:
firehouse58.com onsubmit/onreset event handlers execute script when a submit/reset button is selected within a form. They are called from the <form> tag.

 

Hard Reload
To See Menu

Type a message here.

 

<script language="JavaScript">
<!--

onSubmit
onReset

function redo_(){

var gizmo_ = document.formtest.one.value;

var maker_ = window.open ("","gizmo_","height=200,width=200");

Function redo_  obtains the value of the text object  one, and assigns it to the variable gizmo_.

The window object
open() method is used to create an empty window, which is given the name var maker_.
       

maker_.document.open();

maker_.document.write("<html><head><title>"
+gizmo_+"</title></head><body onBlur='self.close()'>");
maker_.document.write("<center><h2>You Wrote<br>"+gizmo_+"</h2></center>");
maker_.document.write("</body></html>");

maker_.document.close();}

Once the window is open, its document object must also be opened using the document.open() method. This allows the script to write to the new document using the document.write() method.


Ultimately, the document is closed to end writing, using the
document.close() method.

function redu_(){
alert("Message Erased")}

//-->
</script>

redu_ is a simple alert called by the onReset event handler.

<form name="formtest" onSubmit="redo_(); return false;" onReset="redu_()">
<input type="text" name="one" size="20">
<input type="submit"value="Submit">
<input type="reset" value="Reset">
</form>

Both onSubmit & onReset are specified in the form tag. The value of the text object one becomes the title of the new document (Look at the Title Bar) and is written to the new document.

return false prevents the form from actually carrying out any defined action.   

These event handlers can be used to perform various functions. One idea is to use the onsubmit handler to perform multiple tasks, like submitting the form to multiple CGI handlers.

 


[back]   [home]   [next]