LESSON 05B – YOUR OWN FUNCTION

 

WORK (GROUP)

 

TASK

a) Create a form named form1 that has a text field named tf1 and a button.  The button has an onClick attribute that looks like this:

 

onClick= "myFunction();"

 

b) In the head section of your html document, add the following:

 

<script type="text/javascript">

function myFunction()

{

   form1.tf1.value = "Cool! ";

}

</script>

 

Comments:

 

  • The code in the function in the head section is not executed when the webpage is first loaded.

  • The code in the function is only executed when you call the function (in the onClick).

  • Note that the function name in the onClick has to match the name in the head section.

  • This is the first function that you have create!  Hurray!