google+javascriptbanktwitter@js_bankfacebook@jsbankrss@jsbank
Guest, register






JavaScript Code Examples: Part One JavaScript - one of the programming languages in the client-side, an useful programming language for web development. The syntax of JavaScript look like Java but it's easier to learn. And this post is the first part in the series of JavaScript code examples, simple & easy to master.


Label: Code Examples, Part One, Java, programming language, client-side, syntax, series, master

Free iPage Web Hosting for First Year NOW



If you're still looking for a reliable web host provider with affordable rates, why you don't take a little of time to try iPage, only with $1.89/month, included $500+ Free Extra Credits for the payment of 24 months ($45)?

Over 1,000,000+ existisng customers can not be wrong, definitely you're not, too! More important, when you register the web hosting at iPage through our link, we're going to be happy for resending a full refund to you. That's awesome! You should try iPage web hosting for FREE now! And contact us for anything you need to know about iPage.
Try iPage for FREE First Year NOW

Simple alert box:


<html>
<head>
<script type="text/javascript">
function show_alert()
{
 alert("Simple alert box!");
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert" />

</body>
</html>

Alert box with line breaks:


<html>
<head>
<script type="text/javascript">
function show_alert()
{
 alert("This is how simple it is to" + 'n' + "add line breaks to an alert box!");
}

</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert" />

</body>
</html>

Display a confirmation dialog:


<html>
<head>
<script type="text/javascript">

function show_confirm()
{
 var val = confirm("Press a button");
 if (val == true)
 {
 alert("You pressed OK!");
 }
 else
 {
 alert("You pressed Cancel!");
 }
}
</script>
</head>
<body>

<input type="button" onclick="show_confirm()" value="Show a confirm box" />

</body>
</html>

Simple timer:


<html>
<head>
<script type="text/javascript">

function fireTimer()
{
 var t = setTimeout("alert('2 seconds!')",2000);
}
</script>
</head>

<body>

<input type="button" value="Display timer" onClick = " fireTimer()">

</body>
</html>

Determine which mouse button was clicked:


<html>
<head>
<script type="text/javascript">

function whichButtonClick(event)
{
 if (event.button==2)
 {
 alert("You clicked the right mouse button!");
 }
 else
 {
 alert("You clicked the left mouse button!");
 }
}
</script>
</head>

<body onmousedown="whichButtonClick(event)">

</body>

</html>

Reset a form:


<html>
<head>
<script type="text/javascript">
function formReset()
{
 document.getElementById("testform").reset();
}

</script>
</head>

<body>

<form id="testform">
Name: <input type="text" size="20"><br />

Address: <input type="text" size="20"><br />
<br />
<input type="button" onclick="formReset()" value="Reset">

</form>

</body>
</html>

JavaScript by day


Google Safe Browsing McAfee SiteAdvisor Norton SafeWeb Dr.Web