What is a JavaScript function?
Courtesy of http://www.w3schools.com
Steps in creating JavaScript snippets
1. First, create a form in an HTML file and name that form.
<html> <head> <title> </ title > </head> <body> <form name=”FormSample”> <input type=”text” name=”first” onfocus="startCalc();" > <input type=”text” name=”second” onfocus="startCalc();" > <input type=”text” name=”total”> </form> </body> <html>2. After creating the structure of HTML. Now put a javascript function between the <head> and </head> tag.
<script language="javascript"> //calc is the function name function calc(){ //declaring variables one and two one = document. FormSample.first.value; two = document. FormSample.second.value; //apply operations . The parseFloat will convert the number into float data type document. FormSample.total.value =parseFloat (one) + parseFloat (two); } </script>
0 comments:
Post a Comment