0 members and 8,191 guests
No Members online
» Site Navigation
» Stats
Members: 35,443
Threads: 103,072
Posts: 826,684
Top Poster: cc.RadillacVIII (7,429)
|
-
JavaScript library
JavaScript library
Rock, Paper, Scissors 2
Play Rock, Paper, Scissors against your computer. Make your selection and the computer will randomly choose as well and then the game will be scored. Fun!... detail
How to setup
Step 1: Place HTML below in your BODY section
HTML
Code:
<FORM>
Click on either the rock, scissors or paper to make your selection.<br>
Rock beats scissors. Scissors beats paper. Paper beats rock.</p>
<a href="javascript:;" onClick=playGame(1);><img border=0
src="rock.gif" alt="Rock"></a>
<a href="javascript:;" onClick=playGame(2);><img border=0
src="scissors.gif" alt="Scissors"></a>
<a href="javascript:;" onClick=playGame(3);><img border=0
src="paper.gif" alt="Paper"></a><br>
Rock || Scissors || Paper
<p><img border=0 NAME="user_image" src="rock.gif"
> <img border=0 NAME="comp_image"
src="paper.gif" ><br>
You || Computer </p>
<p> <INPUT TYPE="text" SIZE=2 MAXLENGTH=3 NAME="win"
WIN.VALUE="0"> Wins <INPUT TYPE="text" SIZE=2 MAXLENGTH=3
NAME="loss" LOSS.VALUE="0"> Losses <INPUT TYPE="text" SIZE=2
MAXLENGTH=3 NAME="tie" TIE.VALUE="0"> Ties
</p>
<p> <input type=button value="Clear Score"
onClick="clear_score()"></p>
</fieldset>
</center>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
<!-- Hide script from old browsers
// Go the globals
var Players_Choice;
var Computers_Choice;
//pre load image onto user computer
var imageArray = new Array(3);
for (var i=0 ; i<3 ; i++)
imageArray[i] = new Image();
imageArray[0].src="rock.gif";
imageArray[1].src="scissors.gif";
imageArray[2].src="paper.gif";
function playGame(Choice) {
//Wouldn't work unless I did this
Players_Choice=Choice;
// change players image
document.user_image.src = imageArray[Players_Choice-1].src;
//Have comp's choice Change Intermitently (Animate)
intervalID1 = setInterval('SwitchImage();',100);
setTimeout('results(intervalID1);',700);
}
function SwitchImage(){
Computers_Choice=(Math.round(Math.random()*2)+1);
document.comp_image.src = imageArray[Computers_Choice-1].src;
}
function results(intervalID1) {
//Firstly, Stop the animation
clearInterval(intervalID1);
//Player won
if ( (Players_Choice == 1 && Computers_Choice == 2) ||
(Players_Choice == 2 && Computers_Choice == 3) ||
(Players_Choice == 3 && Computers_Choice == 1)){
win.value++;
alert ('You Win'); }
// Its a draw
else if ( Players_Choice == Computers_Choice ){
tie.value++;
alert ('It is a draw'); }
// Player Lost
else {
loss.value++;
alert ('You lost'); }
}
function clear_score() {
// wipe score board
loss.value=0
win.value=0
tie.value=0
}
// End -->
</script>
</form>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
Step 2: downloads
Files
paper1.gif
rock1.gif
scissors1.gif
Originally Posted by Copyright
The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.
-
Binary 101
This program makes it easy to type in binary. You enter the text in the box designated and each key press is translated to binary and added to a box below. The result in the bottom box can then be cop... detail
How to setup
Step 1: Place JavaScript below in your HEAD section
JavaScript
Code:
<SCRIPT>
b1=0
b2=0
b3=0
b4=0
b5=0
b6=0
b7=0
b8=0
function binaryit(e)
{
vtbu=event.keyCode;
window.status=(event.keyCode);
if (vtbu>127) {b1=1; vtbu=vtbu-128};
if (vtbu<128) {if (vtbu>63) {b2=1; vtbu=vtbu-64}};
if (vtbu<64) {if (vtbu>31) {b3=1; vtbu=vtbu-32}};
if (vtbu<32) {if (vtbu>15) {b4=1; vtbu=vtbu-16}};
if (vtbu<16) {if (vtbu>7) {b5=1; vtbu=vtbu-8}};
if (vtbu<8) {if (vtbu>3) {b6=1; vtbu=vtbu-4}};
if (vtbu<4) {if (vtbu>1) {b7=1; vtbu=vtbu-2}};
if (vtbu<2) {if (vtbu>0) {b8=1; vtbu=vtbu-1}};
if (event.keyCode==16) {b1=""; b2=""; b3=""; b4=""; b5=""; b6=""; b7=""; b8=""};
if (event.keyCode==20) {b1=""; b2=""; b3=""; b4=""; b5=""; b6=""; b7=""; b8=""};
if (event.keyCode==17) {b1=""; b2=""; b3=""; b4=""; b5=""; b6=""; b7=""; b8=""};
if (event.keyCode==18) {b1=""; b2=""; b3=""; b4=""; b5=""; b6=""; b7=""; b8=""};
if (event.keyCode==8) {b1=""; b2=""; b3=""; b4=""; b5=""; b6=""; b7=""; b8=""};
b.value=b.value+b1+b2+b3+b4+b5+b6+b7+b8
b1=0; b2=0; b3=0; b4=0; b5=0; b6=0; b7=0; b8=0;
}
</SCRIPT>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
Step 2: Copy & Paste HTML code below in your BODY section
HTML
Code:
<CENTER><INPUT id=input1 onkeyup=binaryit(event); style="WIDTH: 100%"
onfocus="if (this.value=='Enter your text here. Text will be translated into binary in the box below.') {this.value=''}"
value="Enter your text here. Text will be translated into binary in the box below."></CENTER><BR>
<CENTER><TEXTAREA onpaste="return false; " id=b style="WIDTH: 100%; COLOR: lightgreen; HEIGHT: 300px; BACKGROUND-COLOR: black" oncopy="alert('Binary successfully added to clipboard...')" value=""></TEXTAREA><BR><INPUT onclick="b.value=b.value+'00010100'" type=button value="Caps Lock"><INPUT onclick="b.value=b.value+'00010000'" type=button value=Shift><INPUT onclick="b.value=b.value+'00010001'" type=button value=Control><INPUT onclick="b.value=b.value+'00010010'" type=button value=Alt><INPUT onclick="b.value=b.value+'00001000'" type=button value=Backspace></CENTER>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
-
Disable right mouse click script
This is a cross browser DHTML script that will prevent the default right [URL="http://www.javascriptbank.com/javascript/menu/"]JavaScript... detail
How to setup
Step 1: Copy & Paste JavaScript code below in your HEAD section
JavaScript
Code:
<SCRIPT language=JavaScript type=text/javascript>
<!--
function opendetailwindow() {
window.open('','detailwindow','toolbar=no,scrollbars=yes,resizable=no,width=680,height=480');
}
function right(e) {
if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3)) {
alert('© Copyright by iuem');
return false;
}
else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button==2 || event.button == 3)) {
alert('This script disable right click');
return false;
}
return true;
}
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;
// -->
</SCRIPT>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
-
Multilevel Drop Down Horizontal Navigation
This code uses both CSS and JavaScript for creating multilevel drop down navigation menus, submenus will appear when users move mouse over the... detail
How to setup
Step 1: Use CSS code below for styling the script
CSS
Code:
<style type="text/css">
#dd {
margin-left: 25%;
padding: 0 0 20px 0;
}
#dd li {
margin: 0;
padding: 0;
list-style: none;
float: left;
font: bold 11px arial;
}
#dd li a.menu {
display: block;
text-align: center;
background: #5970B2;
padding: 4px 10px;
margin: 0 1px 0 0;
color: #FFF;
width: 60px;
text-decoration: none;
}
#dd li a.menu:hover {
background: #49A3FF;
}
.submenu {
background: #EAEBD8;
border: 1px solid #5970B2;
visibility: hidden;
position: absolute;
z-index: 3;
}
.submenu a {
display: block;
font: 11px arial;
text-align: left;
text-decoration: none;
padding: 5px;
color: #2875DE;
}
.submenu a:hover {
background: #49A3FF;
color: #FFF;
}
</style>
Step 2: Use JavaScript code below to setup the script
JavaScript
Code:
<script type="text/javascript">
// Created by: Konstantin Jagello | http://javascript-array.com/
var TimeOut = 300;
var currentLayer = null;
var currentitem = null;
var currentLayerNum = 0;
var noClose = 0;
var closeTimer = null;
function mopen(n) {
var l = document.getElementById("menu"+n);
var mm = document.getElementById("mmenu"+n);
if(l) {
mcancelclosetime();
l.style.visibility='visible';
if(currentLayer && (currentLayerNum != n))
currentLayer.style.visibility='hidden';
currentLayer = l;
currentitem = mm;
currentLayerNum = n;
} else if(currentLayer) {
currentLayer.style.visibility='hidden';
currentLayerNum = 0;
currentitem = null;
currentLayer = null;
}
}
function mclosetime() {
closeTimer = window.setTimeout(mclose, TimeOut);
}
function mcancelclosetime() {
if(closeTimer) {
window.clearTimeout(closeTimer);
closeTimer = null;
}
}
function mclose() {
if(currentLayer && noClose!=1) {
currentLayer.style.visibility='hidden';
currentLayerNum = 0;
currentLayer = null;
currentitem = null;
} else {
noClose = 0;
}
currentLayer = null;
currentitem = null;
}
document.onclick = mclose;
</script>
Step 3: Copy & Paste HTML code below in your BODY section
HTML
Code:
<ul id="dd">
<li><a href="#" class="menu" id="mmenu1"
onmouseover="mopen(1);"
onmouseout="mclosetime();">Home</a>
<div class="submenu" id="menu1"
onmouseover="mcancelclosetime()"
onmouseout="mclosetime();">
<a href="http://javascriptbank.com/">HTML Tutorials</a>
<a href="http://javascriptbank.com/">DHTML Tutorials</a>
<a href="http://javascriptbank.com/">JavaScript Tutorials</a>
<a href="http://javascriptbank.com/">CSS Tutorials</a>
</div>
</li>
<li><a href="#" class="menu" id="mmenu2"
onmouseover="mopen(2);"
onmouseout="mclosetime();">Download</a>
<div class="submenu" id="menu2"
onmouseover="mcancelclosetime()"
onmouseout="mclosetime();">
<a href="http://javascriptbank.com/">ASP Scripts</a>
<a href="http://javascriptbank.com/">PHP Scripts</a>
<a href="http://javascriptbank.com/">Ajax Scripts</a>
<a href="http://javascriptbank.com/">Perl Scripts</a>
</div>
</li>
<li><a href="#" class="menu">Order</a></li>
<li><a href="#" class="menu">Help</a></li>
<li><a href="#" class="menu" id="mmenu3"
onmouseover="mopen(3);"
onmouseout="mclosetime();">Contact</a>
<div class="submenu" id="menu3"
onmouseover="mcancelclosetime()"
onmouseout="mclosetime();">
<a href="http://javascriptbank.com/">Office</a>
<a href="http://javascriptbank.com/">Sales</a>
<a href="http://javascriptbank.com/">Customer Service</a>
<a href="http://javascriptbank.com/">Shipping</a>
</div>
</li>
</ul>
-
Simple animation
Way of doing this animation is to use separate variables and incrementsto work out the bounces and direction.... detail
How to setup
Step 1: Place JavaScript below in your HEAD section
JavaScript
Code:
<SCRIPT>
//detecting browser to dynamically write appropriate DIVs/LAYERs
N=(navigator.appName.indexOf('Netscape')!=-1&&parseInt(navigator.appVersion)<5)
S=(navigator.appName.indexOf('Netscape')!=-1&&parseInt(navigator.appVersion)>4.9)
M=(navigator.appName.indexOf('Microsoft')!=-1)
Vis=new Array()
Vis[0]=(M||S) ? "hidden" : "hide"
Vis[1]=(M||S) ? "visible" : "show"
function GetDiv(divId,divY,divX,divW,divH,bCol,visb,zInd){
bkCol=(bCol!="")?((N)?" bgColor="+bCol:";background:"+bCol):""
Styl = (M||S) ? "<DIV" : "<LAYER"
if(M||S){
Styl+=" ID="+divId
Styl+=" style='position:absolute;top:"+divY+";left:"+divX+";width:"+divW+";height:"+divH+bkCol
Styl+=";visibility:"+Vis[visb]+";z-index:"+zInd
Styl+="'>"
}
if(N){
Styl+=" ID="+divId
Styl+=" top="+divY+" left="+divX+" width="+divW+" height="+divH+bkCol
Styl+=" visibility="+Vis[visb]+" z-index="+zInd
Styl+=">"
}
document.writeln(Styl)
}
function EndDiv(){
(M||S)? document.writeln("</DIV>"): document.writeln("</LAYER>")
}
function PutIt(ID,dX,dY){
if(N){
document.layers[ID].left=dX
document.layers[ID].top=dY
}
if(M){
document.all[ID].style.left=dX
document.all[ID].style.top=dY
}
if(S){
document.getElementById(ID).style.left=dX
document.getElementById(ID).style.top=dY
}
}
function ShowHide(ID,vs){
if(N){
document.layers[ID].visibility=Vis[vs]
}
if(M){
document.all[ID].style.visibility=Vis[vs]
}
if(S){
document.getElementById(ID).style.visibility=Vis[vs]
}
}
function Xof(ID){
if(N){
return document.layers[ID].left
}
if(M){
return document.all[ID].style.left
}
if(S){
return document.getElementById(ID).style.left
}
}
function Yof(ID){
if(N){
return document.layers[ID].top
}
if(M){
return document.all[ID].style.top
}
if(S){
return document.getElementById(ID).style.top
}
}
function Zind(ID,zz){
if(N){
document.layers[ID].zIndex=zz
}
if(M){
document.all[ID].style.zIndex=zz
}
if(S){
document.getElementById(ID).style.zIndex=zz
}
}
function ChangeCol(ID,colrx){
if(M)document.all[ID].style.background=colrx
if(N)document.layers[ID].bgColor=colrx
if(S)document.getElementById(ID).style.background=colrx
}
function DivWrite(IdName,Str) {
if (N){
document.layers[IdName].document.write(Str)
document.layers[IdName].document.close()
}
if(M) document.all[IdName].innerHTML=Str
if(S) document.getElementById(IdName).innerHTML=Str
}
</SCRIPT>
<SCRIPT>
// The laydiv.js file above has functions that
// 1. Write <DIV>s for Internet explorer and <LAYER>s for Netscape4.7
// 2. Calculate and return many (browser specific) properties of these objects like
// z-index, pixeltop, pixelleft, visibility, etc,...
GetDiv("Flyer",150,450,50,70,'',1,2)
document.write("<img src=bong.gif>")
EndDiv()
// The code above writes a div at coords 450,150 with
// width 50, height 70, bgcolor nil (clear), visibility 1, z-Index 2
// that has an image of a ball on it
dx=5 //first horizontal direction is left by 5
dy=5 //first vertical direction is down by 5
curX=350 //the original x-coord of object
curY=150 //the original y-coord of object
function Fly(){
curX+=dx //work out next x-coord
curY+=dy //work out next y-coord
if(curX==50||curX==600)dx=-dx //if x-coord is at bound then bounce by changing direction
if(curY==50||curY==400)dy=-dy //ditto
PutIt("Flyer",curX,curY) //Put object 'Flyer' at coord curX,curY
}
Cont=setInterval('Fly()',20) //Continue the moving by setting interval to call the function
</SCRIPT>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
-
Tic-Tac-Toe: using image
Try your luck at an interactive game of good old tic-tac-toe!! Automatic scoring and alternating 'first moves' are built in. Fun!... detail
How to setup
Step 1: Place JavaScript below in your HEAD section
JavaScript
Code:
<script language="JavaScript">
// Maximilian Stocker (maxstocker@reallyusefulcomputing.com)
<!-- Begin
var x = "x.jpg";
// Location of where you uploaded your site's x.jpg image
var o = "o.jpg";
// Location of where you uploaded your site's o.jpg image
var blank = "blank.jpg";
// Location of where you uploaded your site's blank.jpg image
var pause = 0;
var all = 0;
var a = 0;
var b = 0;
var c = 0;
var d = 0;
var e = 0;
var f = 0;
var g = 0;
var h = 0;
var i = 0;
var temp="";
var ok = 0;
var cf = 0;
var choice=9;
var aRandomNumber = 0;
var comp = 0;
var t = 0;
var wn = 0;
var ls = 0;
var ts = 0;
function help() {
alert("Welcome to Tic-Tac-Toe! You play as the X's and the computer is the O's. Select the square you want to put your X into by clicking them. You cannot occupy a square that is already occupied. The first player to get three squares in a row wins. Good Luck!!")
}
function logicOne() {
if ((a==1)&&(b==1)&&(c==1)) all=1;
if ((a==1)&&(d==1)&&(g==1)) all=1;
if ((a==1)&&(e==1)&&(i==1)) all=1;
if ((b==1)&&(e==1)&&(h==1)) all=1;
if ((d==1)&&(e==1)&&(f==1)) all=1;
if ((g==1)&&(h==1)&&(i==1)) all=1;
if ((c==1)&&(f==1)&&(i==1)) all=1;
if ((g==1)&&(e==1)&&(c==1)) all=1;
if ((a==2)&&(b==2)&&(c==2)) all=2;
if ((a==2)&&(d==2)&&(g==2)) all=2;
if ((a==2)&&(e==2)&&(i==2)) all=2;
if ((b==2)&&(e==2)&&(h==2)) all=2;
if ((d==2)&&(e==2)&&(f==2)) all=2;
if ((g==2)&&(h==2)&&(i==2)) all=2;
if ((c==2)&&(f==2)&&(i==2)) all=2;
if ((g==2)&&(e==2)&&(c==2)) all=2;
if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g != 0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3;
}
function logicTwo() {
if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C";
if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B";
if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A";
if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G";
if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D";
if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A";
if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I";
if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E";
if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A";
if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H";
if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E";
if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B";
if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F";
if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E";
if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D";
if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I";
if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H";
if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G";
if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I";
if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F";
if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C";
if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C";
if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E";
if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G";
}
function logicThree() {
if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C";
if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B";
if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A";
if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G";
if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D";
if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A";
if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I";
if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E";
if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A";
if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H";
if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E";
if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B";
if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F";
if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E";
if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D";
if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I";
if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H";
if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G";
if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I";
if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F";
if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C";
if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C";
if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E";
if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G";
}
function clearOut() {
document.game.you.value="0";
document.game.computer.value="0";
document.game.ties.value="0";
}
function checkSpace() {
if ((temp=="A")&&(a==0)) {
ok=1;
if (cf==0) a=1;
if (cf==1) a=2;
}
if ((temp=="B")&&(b==0)) {
ok=1;
if (cf==0) b=1;
if (cf==1) b=2;
}
if ((temp=="C")&&(c==0)) {
ok=1;
if (cf==0) c=1;
if (cf==1) c=2;
}
if ((temp=="D")&&(d==0)) {
ok=1;
if (cf==0) d=1;
if (cf==1) d=2;
}
if ((temp=="E")&&(e==0)) {
ok=1;
if (cf==0) e=1;
if (cf==1) e=2;
}
if ((temp=="F")&&(f==0)) {
ok=1
if (cf==0) f=1;
if (cf==1) f=2;
}
if ((temp=="G")&&(g==0)) {
ok=1
if (cf==0) g=1;
if (cf==1) g=2;
}
if ((temp=="H")&&(h==0)) {
ok=1;
if (cf==0) h=1;
if (cf==1) h=2;
}
if ((temp=="I")&&(i==0)) {
ok=1;
if (cf==0) i=1;
if (cf==1) i=2;
}
}
function yourChoice(chName) {
pause = 0;
if (all!=0) ended();
if (all==0) {
cf = 0;
ok = 0;
temp=chName;
checkSpace();
if (ok==1) {
document.images[chName].src = x;
}
if (ok==0)taken();
process();
if ((all==0)&&(pause==0)) myChoice();
}
}
function taken() {
alert("That square is already occupied. Please select another square.")
pause=1;
}
function myChoice() {
temp="";
ok = 0;
cf=1;
logicTwo();
logicThree();
checkSpace();
while(ok==0) {
aRandomNumber=Math.random()
comp=Math.round((choice-1)*aRandomNumber)+1;
if (comp==1) temp="A";
if (comp==2) temp="B";
if (comp==3) temp="C";
if (comp==4) temp="D";
if (comp==5) temp="E";
if (comp==6) temp="F";
if (comp==7) temp="G";
if (comp==8) temp="H";
if (comp==9) temp="I";
checkSpace();
}
document.images[temp].src= o;
process();
}
function ended() {
alert("The game has already ended. To play a new game click the Play Again button.")
}
function process() {
logicOne();
if (all==1){ alert("You won, congratulations!"); wn++; }
if (all==2){ alert("Gotcha! I win!"); ls++; }
if (all==3){ alert("We tied."); ts++; }
if (all!=0) {
document.game.you.value = wn;
document.game.computer.value = ls;
document.game.ties.value = ts;
}
}
function playAgain() {
if (all==0) {
if(confirm("This will restart the game and clear all the current scores. OK?")) reset();
}
if (all>0) reset();
}
function reset() {
all = 0;
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
g = 0;
h = 0;
i = 0;
temp="";
ok = 0;
cf = 0;
choice=9;
aRandomNumber = 0;
comp = 0;
document.images.A.src= blank;
document.images.B.src= blank;
document.images.C.src= blank;
document.images.D.src= blank;
document.images.E.src= blank;
document.images.F.src= blank;
document.images.G.src= blank;
document.images.H.src= blank;
document.images.I.src= blank;
if (t==0) { t=2; myChoice(); }
t--;
}
// End -->
</script>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
Step 2: Copy & Paste HTML code below in your BODY section
HTML
Code:
<form name="game">
<table border="0">
<tbody><tr><td>
<table border="1">
<tbody><tr>
<td><a href="javascript:yourChoice('A')"><img src="blank.jpg" border="0" height="100" width="100" name="A" alt="Top-Left"></a></td>
<td><a href="javascript:yourChoice('B')"><img src="o.jpg" border="0" height="100" width="100" name="B" alt="Top-Center"></a></td>
<td><a href="javascript:yourChoice('C')"><img src="blank.jpg" border="0" height="100" width="100" name="C" alt="Top-Right"></a></td>
</tr>
<tr>
<td><a href="javascript:yourChoice('D')"><img src="blank.jpg" border="0" height="100" width="100" name="D" alt="Middle-Left"></a></td>
<td><a href="javascript:yourChoice('E')"><img src="blank.jpg" border="0" height="100" width="100" name="E" alt="Middle-Center"></a></td>
<td><a href="javascript:yourChoice('F')"><img src="x.jpg" border="0" height="100" width="100" name="F" alt="Middle-Right"></a></td>
</tr>
<tr>
<td><a href="javascript:yourChoice('G')"><img src="blank.jpg" border="0" height="100" width="100" name="G" alt="Bottom-Left"></a></td>
<td><a href="javascript:yourChoice('H')"><img src="blank.jpg" border="0" height="100" width="100" name="H" alt="Bottom-Center"></a></td>
<td><a href="javascript:yourChoice('I')"><img src="blank.jpg" border="0" height="100" width="100" name="I" alt="Bottom-Right"></a></td>
</tr>
</tbody></table>
</td>
<td>
<table>
<tbody><tr><td><input type="text" size="5" name="you"></td><td>You</td></tr>
<tr><td><input type="text" size="5" name="computer"></td><td>Computer</td></tr>
<tr><td><input type="text" size="5" name="ties"></td><td>Ties</td></tr>
</tbody></table>
</td>
</tr></tbody></table>
<input type="button" value="Play Again" onclick="playAgain();">
<input type="button" value="Game Help" onclick="help();">
</form>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
-
JavaScript Countdown Timer
This JavaScript displays a countdown timer and alerts the user when the timer reaches zero. It then redirects to another Web ... detail
How to setup
Step 1: Use CSS code below for styling the script
CSS
Code:
<style type="text/css">
#txt {
border:none;
font-family:verdana;
font-size:16pt;
font-weight:bold;
border-right-color:#FFFFFF
}
</style>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
Step 2: Use JavaScript code below to setup the script
JavaScript
Code:
<script language="javascript">
// Created by: Neill Broderick :: http://www.bespoke-software-solutions.co.uk/downloads/downjs.php
var mins
var secs;
function cd() {
mins = 1 * m("10"); // change minutes here
secs = 0 + s(":01"); // change seconds here (always add an additional second to your total)
redo();
}
function m(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(0, i));
}
function s(obj) {
for(var i = 0; i < obj.length; i++) {
if(obj.substring(i, i + 1) == ":")
break;
}
return(obj.substring(i + 1, obj.length));
}
function dis(mins,secs) {
var disp;
if(mins <= 9) {
disp = " 0";
} else {
disp = " ";
}
disp += mins + ":";
if(secs <= 9) {
disp += "0" + secs;
} else {
disp += secs;
}
return(disp);
}
function redo() {
secs--;
if(secs == -1) {
secs = 59;
mins--;
}
document.cd.disp.value = dis(mins,secs); // setup additional displays here.
if((mins == 0) && (secs == 0)) {
window.alert("Time is up. Press OK to continue."); // change timeout message as required
// window.location = "yourpage.htm" // redirects to specified page once timer ends and ok button is pressed
} else {
cd = setTimeout("redo()",1000);
}
}
function init() {
cd();
}
window.onload = init;
</script>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
Step 3: Copy & Paste HTML code below in your BODY section
HTML
Code:
<form name="cd">
<input id="txt" readonly="true" type="text" value="10:00" border="0" name="disp">
</form>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
-
Image slideshow transition
This JavaScript creates slideshow effect with one of transitions.... detail
How to setup
Step 1: Copy & Paste JavaScript code below in your HEAD section
JavaScript
Code:
<script LANGUAGE="JavaScript1.1">
<!-- Beginning of JavaScript -
messages = new Array()
//anh dung de tao hieu ung
messages[0] = "<img src=logojs.gif>"
messages[1] = "<img src=photo1.jpg>"
messages[2] = "<img src=photo2.jpg>"
messages[3] = "<img src=photo3.jpg>"
messages[4] = "<img src=photo4.jpg>"
var i_messages = 0
var timer
function dotransition() {
if (document.all) {
content.filters[0].apply()
content.innerHTML = messages[i_messages]
content.filters[0].play()
if (i_messages >= messages.length-1) {
i_messages = 0
}
else {
i_messages++
}
}
if (document.layers) {
document.nn.document.write("<table cellspacing=2 cellpadding=2 border=0><tr><td align=left>"+messages[i_messages]+"</td></tr></table>")
document.close()
if (i_messages >= messages.length-1) {
i_messages = 0
}
else {
i_messages++
}
}
timer = setTimeout("dotransition()",5000)
}
// - End of JavaScript - -->
</script>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
Step 2: Copy & Paste HTML code below in your BODY section
HTML
Code:
<BODY onload="dotransition()">
<DIV id=content style="position: relative; width:160px; height:240px; text-align:center; filter: revealTrans(Transition=12, Duration=3)"></DIV>
</BODY>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
-
Make link open in new tab/window
Use this simple JavaScript to make all links on your web pages open in new tab/window. Script is easy to setup, you should save them into a f... detail
How to setup
Step 1: Copy & Paste JavaScript code below in your HEAD section
JavaScript
Code:
<script language=javascript>
/*
Kevin Yank
http://www.sitepoint.com/authorcontact/48
*/
function externalLinks()
{
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++)
{
var anchor = anchors[i];
if(anchor.getAttribute("href"))
anchor.target = "_blank";
}
}
window.onload = externalLinks;
</script>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
Step 2: Copy & Paste HTML code below in your BODY section
HTML
Code:
<a href="http://javascriptbank.com/">Home</a> |
<a href="http://javascriptbank.com/4rum/">Forum</a> |
<a href="http://javascriptbank.com/javascript/">JavaScript</a> |
<a href="http://javascriptbank.com/service/">Services</a> |
<a href="http://javascriptbank.com/javascript/submit-javascript-bank.html">Submit script</a> |
<a href="http://javascriptbank.com/thietkeweb/javascriptmall/">Documentary</a> |
<a href="http://javascriptbank.com/javascript/contact-javascript-bank.html">Contact us</a> |
<a href="http://javascriptbank.com/javascript/aboutus-javascript-bank.html">About us</a>
<!--
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
-->
-
AJAX Page Content Loader
AJAX - a very great web development technology nowaday. Use this AJAX in order to load XML and HTML files on the same website with XMLHttpRequest. And in the <code>body... detail at JavaScriptBank.com - 2.000+ free JavaScript codes
How to setup
Step 1: Place CSS below in your HEAD section
CSS
Code:
<style type="text/css">
<!--
#contentLYR {
position:relative;/*
width:200px;
height:115px;
left: 200px;
top: 200px;*/
z-index:1;
}
-->
</style>
Step 2: Place JavaScript below in your HEAD section
JavaScript
Code:
<script type="text/javascript">
<!-- Begin
/*
This script downloaded from www.JavaScriptBank.com
Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
*/
// Created by: Eddie Traversa (2005) :: http://dhtmlnirvana.com/
function ajaxLoader(url,id) {
if (document.getElementById) {
var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
}
if (x) {
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200) {
el = document.getElementById(id);
el.innerHTML = '<JavaScriptBank>This is content of demo.xml file</JavaScriptBank>';//x.responseText;
}
}
x.open("GET", url, true);
x.send(null);
}
}
//-->
</script>
Step 3: Copy & Paste HTML code below in your BODY section
HTML
Code:
<div id="contentLYR"></div>
<script>window.onload = function(){ajaxLoader('demo.xml','contentLYR');}</script>
Step 4: downloads
Files
demo.xml
Similar Threads
-
By mannos in forum Resources
Replies: 9
Last Post: 06-25-2007, 11:17 AM
-
By Akkad in forum Other Tutorials
Replies: 0
Last Post: 12-04-2006, 10:56 PM
-
By ChaosDealer73 in forum Other Tutorials
Replies: 1
Last Post: 10-20-2005, 01:17 PM
-
By 1337elite in forum Support
Replies: 0
Last Post: 06-29-2005, 03:27 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|