Adding Dynamic Behavior to Forms


Assume the following form has been created:

Here is the code that produced this form:

<FORM>
  <INPUT TYPE=text 
         NAME=myTextBox 
         SIZE=30>
   
  <P>
  <INPUT TYPE=button
         VALUE="myButton"
         onclick="myFunction(this.form)">
 </FORM>


When the button is clicked, a function named "myFunction" is called - and told to operate on this form. The argument "this.form" is passed to myFunction so it knows to use the current form.

Here is some code for "myFunction":

   	function myFunction(form) {
	     form.myTextBox.value = ""	
		 return ""
	}


Notes:
      form.myTextBox.value = 2	


Instructing Your Page to Run a Function Continuously:

function Cycle(form) {
   ...   
   setTimeout("Cycle(form)",1000)
   return ""
}

Notes:


Instructing your page to run your function as soon as the page is loaded:

<BODY onLoad="Cycle(document.form[0])")

   <FORM>
      ...
   </FORM>

</BODY>

 

Notes:


Using random numbers to generate random events: