You place JavaScript code between the <script language="JavaScript"> tag and the </SCRIPT> tag.
Here is an example of JavaScript code. This code would check to see if there is a number entered into a text box (or anything at all) and then divides the number by two before alerting it in an alert box. (text box and button not included)
<script language="JavaScript">
function doitforme()
{
if(Formname.textboxname.value.length == 0)
{
alert("You have nothing entered!")
} else {
var number = parseInt(Formname.textboxname.value)
if(isNaN(number))
{
alert("There is no number there!")
} else {
var newnum = number/2
alert("The new number is "+newnum+".")
}
}
}
You do not have to understand the code, just note how it is different from HTML. Remember this comes in the website.
Have fun with JavaScript! Good luck!

No comments:
Post a Comment