You are on page 1of 3

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

<!-- <!--
var myColor = "Red"; var myColor = "Red";

switch (myColor) if (myColor == "Blue") {


{ document.write("Just like the
case "Blue": sky!");
document.write("Just like the }
sky!"); else if (myColor = "Red") {
break document.write("Just like
case "Red": shiraz!");
document.write("Just like }
shiraz!"); else {
break document.write("Suit yourself
default: then...");
document.write("Suit yourself }
then..."); //-->
} </script>
//-->
</script>
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
try document.write("They call it
{ an \"escape\" character");
document.write("My bank balance is $" + //-->
myBankBalance); </script>
}
catch(err) o/p: They call it an "escape" character
{
document.write("Sorry, an error has var currentDate = new Date()
occurred"); var day = currentDate.getDate()
document.write("...but hey, don't let that var month = currentDate.getMonth()
stop you!"); var year = currentDate.getFullYear()
} document.write("<b>" + day + "/" +
//--> month + "/" + year + "</b>")
</script>
output: Sorry, an error has occurred...but hey, don't let that Results in this...25/10/2010
stop you!
var currentTime = new Date()
var hours = currentTime.getHours() <a href="JavaScript:void(0);"
var minutes = currentTime.getMinutes() ondblclick="alert('Well done!')">Double Click
Me!</a>
var suffix = "AM";
if (hours >= 12) { Result: Double Click Me!
suffix = "PM";
hours = hours - 12; <script type="text/javascript">
} function showMsg(){
if (hours == 0) { var userInput =
hours = 12; document.getElementById('userInput').valu
} e;

if (minutes < 10)


document.getElementById('userMsg').innerH
minutes = "0" + minutes
TML = userInput;
}
document.write("<b>" + hours + ":" +
</script>
minutes + " " + suffix + "</b>")
<input type="input" maxlength="40"
id="userInput" onkeyup="showMsg()"
Results in this... value="Enter text here..." />
<p id="userMsg"></p>
10:10 AM Result: here is tb
<script type="text/javascript">
function Msg1(){ shefalifdsfsfsfffff
<script type="text/javascript">
document.getElementById('myText').innerHTML function changeColor(){
= 'Thanks!'; var newColor =
} document.getElementById('colorPicker')
function Msg2(){ .value;
document.getElementById('colorMsg').style
document.getElementById('myText').innerHTML .color = newColor;
= 'Try message 1 again...'; }
} </script>
</script> <p id="colorMsg">Choose a color...</p>
<input type="button" onclick="Msg1()" <select id="colorPicker"
value="Show Message 1" /> onchange="JavaScript:changeColor()">
<input type="button" onclick="Msg2()" <option value="#000000">Black</option>
value="Show Message 2" /> <option value="#000099">Blue</option>
<p id="myText"></p> <option value="#990000">Red</option>
<option value="#009900">Green</option>
</select>
Result: here 2 buttons r there

Result: Choose a color...


Try message 1 again...

Black

var faq = new Array(3)


<html>
for (i=0; i <3; i++) <head>
faq[i]=new Array(3) <body>
<div style="text-align:center;padding:10px;">
faq[0][1] = "Arrays" <h1>Amazing Web Page</h1>
faq[0][2] = "What is an array?"
<script type="text/javascript">
faq[0][3] = "An ordered stack of data"
alert('But wait, there\'s more...');
</script>
faq[1][1] = "Arrays"
faq[1][2] = "How to create arrays?"
<p><a href="JavaScript:self.close();">Close This Silly Page!
faq[1][3] = "Assign variable name to array </a></p>
object, </div>
then assign values to the </body>
array." </html>

faq[2][1] = "Arrays"
faq[2][2] = "What are two dimensional
arrays?"
faq[2][3] = "An ordered grid of data"

<script language="javascript" type="text/javascript" >


function welcomeMsg(promptMsg)
{
visitorName = prompt(promptMsg, '');
alert("Welcome " + visitorName + "," + "\n\n" +
"You are currently visiting one of the best web development
sites on the net! Hope you find Quackit useful!" + "\n\n" +
"Hey " + visitorName + ", don't forget to recommend us to
your friends!");
}
</script>
<form>
<input type="button" onclick="welcomeMsg('What is your
name?');" value="Read our Welcome Message!" />
</form>
<script language="javascript" type="text/javascript" >
function jumpto(selectedURL){
if (document.navForm.jumpmenu.value != "null")
{
var confirmLeave = confirm('Are you sure
you want to leave the Quackit website?');
if (confirmLeave==true)
{
document.location.href =
selectedURL
}
else
{
return false;
}
}
}
</script>
<p>Visit one of these excellent websites:</p>
<form name="navForm">
<select name="jumpmenu"
onChange="jumpto(document.navForm.jumpmenu.options[
document.navForm.jumpmenu.options.selectedIndex].value
)">
<option>Jump to...</option>
<option
value="http://www.zappyhost.com">ZappyHost</option>
<option value="http://www.code-
generator.net">Code Generator</option>
<option value="http://www.natural-
environment.com">Natural Environment</option>
<option value="http://www.great-
workout.com">Great Workout</option>
</select>
</form>

You might also like