JavaScript - 2 Noobie Functions
hey , i got 2 function , the one working and the other one is'nt
heres the functions : Code: var toDisplay = "f"; function human(){ var toAdd = toDisplay.substring(0,1); setTimeout(human , 500); document.getElementById('box').innerHTML += toAdd; } human(); // works (display "f" every half a sec) function human2(toDisplay2){ var toAdd = toDisplay2.substring(0,1); var t = setTimeout("human2(toDisplay2)" , 500); document.getElementById('box').innerHTML += toAdd; } human2("dsd"); // not working (only display "d" and stop) the first function works ( keep printing "f" every 0.5 sec ) the second function only work once and than stop ( print "d" and than stop ) what's the problem with the second function? thanks , Mor. Similar TutorialsHello, I am working on making a starting hub website for myself. I have four images that are the background image in a table. I would like to have all four pictures be something different every time the page is loaded. Currently I can only get one image to rotate and the rest just show blank with no picture at all. I would like to have all four pictures show and have them rotate their image on page refreshes. Is this possible using just Javascript and HTML? Here is my code: This is my Javascript Code: <script type="text/javascript"><!-- var backgroundImages=new Array(5); backgroundImages[0]="images/backgrounds/firework.jpg"; backgroundImages[1]="images/backgrounds/friends.jpg"; backgroundImages[2]="images/backgrounds/firework.jpg"; backgroundImages[3]="images/backgrounds/friends.jpg"; backgroundImages[4]="images/backgrounds/tigers.jpg"; onload=function(){ var e=(document.getElementById)?document.getElementById("myTableId"):(document.all)?document.all.myTableId:(document.layers)?document.myTableId:null; if(!e)return true; e.style.backgroundImage="url("+backgroundImages[Math.floor(Math.random()*backgroundImages.length)]+")"; } //--></script> and here is how I am calling the elements inside of the table: Code: <table cellpadding="1" cellspacing="0" border="0"> <tr> <td id="myTableId" width="302" height="422"> <a href="http://www.meachaverse.com/" target="_blank">meachaverse</a><br /> <a href="http://www.mittnmusic.com/" target="_blank">mittnmusic</a><br /> <a href="http://worldbycarey.blogspot.com/" target="_blank">worldbycarey</a><br /> <a href="http://www.certaingravity.com" target="_blank">certaingravity</a><br /> </td> <td id="myTableId" width="302" height="422"> <a href="http://www.meachaverse.com/" target="_blank">meachaverse</a><br /> <a href="http://www.mittnmusic.com/" target="_blank">mittnmusic</a><br /> <a href="http://worldbycarey.blogspot.com/" target="_blank">worldbycarey</a><br /> <a href="http://www.certaingravity.com" target="_blank">certaingravity</a><br /> </td> ANY Help with this would be much appreciated!!! The site is http://davenport80.comli.com I'm completely new to Java Script, but about a year ago I decided to learn how to build a website from scratch. I am confident with HTML and CSS, but Java seems to be flying over my head. Could anybody possibly help me with my coding? I'm sure the problem is obvious, but I don't know if this is the right place to post this sort of beginnier question. So if it is not, please redirect me to where I can. Thanks a lot! Quote: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <title></title> </head> <body> <script type="text/javascript"> function addzero(zero) { return zero; } var d = new Date(); var time=d.getHours function tod1 () { document.write("The time is "); document.write(addzero(d.getHours())); document.write(":"); document.write(addzero(d.getMinutes())); } function tod2 () { document.write("The time is "); document.write(addzero(d.getHours()+1)); document.write(":"); document.write(addzero(d.getMinutes())); } function tod3 () { document.write("The time is "); document.write(addzero(d.getHours()+2)); document.write(":"); document.write(addzero(d.getMinutes())); } function tod4 () { document.write("The time is "); document.write(addzero(d.getHours()+3)); document.write(":"); document.write(addzero(d.getMinutes())); } if (time>10) { alert("Good morning"); } </script> <p id="city"></p> <form name="form" action="wtf.php" method="post"> Vancouver: <input type="radio" name="city" id="Vancouver" onchange="tod1()"> Calgary: <input type="radio" name="city" id="Calgary" onchange="tod2()"> Winnipeg: <input type="radio" name="city" id="Winnipeg" onchange="tod3()"> Toronto: <input type="radio" name="city" id="Toronto" onchange="tod4()"> </form> </body> </html> Code: <body> <title>Array Games</title> <script type="text/javascript"> var City = new Array(); var uNoGo = false; var endIt = false; alert("Hello! This program does two things! One, it asks for five cities. It stores the city names in an array cause arrays are what we're doing this chapter. Then it tells you the city names VIA said array! Secondly, it asks you for a number between 1 and 250,00. It then checks if the number is a perfect square! Uses Binary Search. ;)"); while(!endIt) { for(var i=0;i<5;i++) { City[i] = prompt("Please enter in a city name!",""); } for(var i=1;i<6;i++) { var msg += "\n" + "Your number " + i + " city is: " + City[i-1]; } alert(msg); while(!uNoGo) { var Sq = prompt("Enter in a number between 1 and 250,000.", ""); if(Sq >= 1 && Sq <= 250000) { var Mebe = Math.sqrt(Sq); if(Math.round(Mebe)*Math.round(Mebe)==Sq) { alert("Gratz! Your number is a perfect square."); } else { alert("We're sorry, the number you have chosen is not a perfect square. It may be a circle but we don't know. Good luck next time!"); } uNoGo = true; } else { alert("You entered in something invalid! WARNING NUCLEAR MELTDOWN IMMINENT!"); } } var cont = prompt("Do you want to ride again? Type N to stop, anything else to continue.",""); if(cont=="\\") { alert("As you came around the corner... SSSSSSSSSSSSSSSSSS. There goes your dirt house."); } if(cont=="N" || cont=="n") { endIt=true; alert("Thank you, come again."); } } </script> </body> </html> I am trying make this codes work in a browser as javascript but nothing shows up hey all, what it says in the title, this block of code wont work and i dont know why. the first prompt box appears but not the "can vote, but can't drink" reply. can anyone offer any ideas? <!DOCTYPE html> <html> <head> <title>legal age</title> <script type="text/javascript"> var your_age = prompt("how old are you?"); if ((age > 18) && (age < 21)) { document.writeln("can vote, but can't drink."); } </script> </body> </html> kind regards, Redd . Just wondering if it's possible to prevent a page displaying until the content is fully loaded. I have a form with a load of check boxes that reloads itself on each user click and it would be nice to smooth things out a little, e.g. hold a screenshot of the page until the reload is complete and then instantly show that one. Stupid question? Cheers, Nick Hi, I have written a number of functions designed to return frequency data on 1000 randomly chosen numbers using different math functions for the rounding. I would like to include all of these functions within the wrapper of another function so that only one call is needed to get returns from all of the 'inner' functions. However, while each of the functions works in isolation, the moment I wrap them in another function they stop working. The following code is one of the functions 'frequencyWrapperOne' that has been wrapped in the function 'testWrapper'. A call to testWrapper does nothing. Can anyone see what I'm doing wrong? Code: function testWrapper() { function frequencyWrapperOne() { var numberArrayOne = new Array(0,0,0); for (var i = 0; i < 1000; i = i + 1) { var chosenNumber = Math.floor(Math.random() * 3); if (chosenNumber == 0) { numberArrayOne[0] = numberArrayOne[0] + 1; } if (chosenNumber == 1) { numberArrayOne[1] = numberArrayOne[1] + 1; } if (chosenNumber == 2) { numberArrayOne[2] = numberArrayOne[2] + 1; } } return window.alert(numberArrayOne.join(',')); } } testWrapper(); Thanks. Ok here is what I have so far, my ending part of my Call Function I think is ok. for my main function. I think I misplaced the { and } I will show you all the codes I have for my main function this is what I have I think I did misplace something but I can not pin point where that one small things should be Code: unction showResults(race,name,party,votes) { // script element to display the results of a particular race var totalV = totalVotes(votes); document.write("<h2>" + race + "</h2>"); document.write("<table cellspacing='0'>"); document.write("<tr>"); document.write("<th>Candidate</th>"); document.write("<th class ='num'>Votes</th>"); document.write("<th class='num'>%</th>"); document.write("</tr>"); } for (var i=0; i < name.length; i++) { document.write("<tr>"); document.write("<td>" name[i] + "(" + party[i] + ")</td>"); document.write("td class='num'>" + votes[i] + "</td>"); var percent=calcPercent(votes[i], totalV) document.write("<td class='num'>(" + percent +"%)</td>"); createBar(party[i],percent) document.write("</tr>"); } document.write("</table>"); } </script> Just wondering if i misplaced any ; or { or } anywhere suggestions? Here is my call function Code: <script type="text/javascript"> showResults(race[0],name1,party1,votes1); showResults(race[1],name2,party2,votes2); showResults(race[2],name3,party3,votes3); showResults(race[3],name4,party4,votes4); showResults(race[4],name5,party5,votes5); </script> I been going over this, I can not seem to figure out what { i might be missing? Thanks Is there a way to activate a function from another function? It has to be in the script tag, it can't be in the HTML section. Can I use something similar to this following code? If not, can anyone give me some help? I have tried to do it various ways, and have looked it up a few times, but to no avail. Can I use something similar to this following code? If not, can anyone give me some help? if (condition) {activate functionname();} Any help I can get would be appreciated. Thanks a lot to anyone who can help. I would really like to thank the guys that have been helping me. I think my brain would have exploded otherwize. Some of the problems have been simple misspellings, but when you have been staring at the same thing for hours it can sorta slip by. HOPEFULLY this will be the last thing that I need some help with. Bascially Im not sure if Im using the function command properly. When Submit Details is click it should validate the form and then when Calculate is pressed calculate the form (obviously). I think maybe my var Array table is wrong? And the way the functions are set out doesnt seem it sit right. Code: <script type="text/javascript"> var element; var itemArray = new Array(); itemArray [0] = "Bike" //not sure if these are properly writen?// itemArray [1] = "TV" itemArray [2] = "iPod" itemArray [3] = "Car" var flag="OK"; var count = 0 document.write ("<form name='myform'><br><table>"); while (count <= 3) { if (count < 3) { document.write ("<tr><td><value>Enter money from " + itemArray [count] + " sale.</td><td><input type='text' name=" + itemArray [count] + "></td></tr>"); count++ } else { document.write ("<tr><td><value>Enter the price of " + itemArray [count] + ".</td><td><input type='text' name=" + itemArray [count] + "></td></tr>"); document.write ("<tr><td><input type='submit' value='Submit Details' onClick='validateform'</td></tr>"); document.write ("<tr><td><input type='submit' value='Calculate Details' onClick='calculateform'</td></tr></table></form>"); count++ } } function validateform() //<=== doesnt run { element=document.getElementsByTagName ('input'); for (counter=0; counter<element.length; counter++) { switch (element[counter].type) { case "submit": break; default: if (isNaN(element[counter].value) || (element[counter].value == "") ) { alert("You need to enter a number into " + element[counter].name); flag="NotOK" } else { Bike=element[0].value; TV=element[1].value; iPod=element[2].value; Car=element[3].value; } break; } } } function calculateform() //<=== Doesnt run either { if (flag=="OK") { if ( (Number(element[Bike])) && (Number(element[TV])) && (Number(element[iPod])) && (Number(element[Car])) ) //<========= Gets Bike is not defined error easy// { TotalMoney= parseFloat (Bike) + parseFloat (TV) + parseFloat (iPod) if (TotalMoney >= Car) { alert ("The total money is " + TotalMoney + " and the car price is " + Car + " and you can afford the car") } else { alert ("The total money is " + TotalMoney + " and the car price is " + Car + " and you cannot afford the car") } } } } </script> Hi, I am creating a mashUp with google maps and have a function that creates the map, marker, infowindow and all works great. I want to add more functions to that functions file. Do I start with another function Name() put my function in the {} and then I am going to use the onclick event when I want the function to run. I also am going to add more functions to this file Is that the correct way to keep adding functions? And what is the best way of calling them in my html file? Answers and examples would be great thank you I'm a newbie student coder for now, hoping to enter the wonderful world of software engineering in another year. I put together a very simple site for a class and all is well, but my "Contact SRS" form doesn't seem to want to run my JavaScript code even though I've used a JS debugger which returned no errors. When I click the Submit button it's supposed to validate the form. But I keep getting "Error on page" in the bottom IE 7 message bar (where it usually says "Done" when you load a page). There is another function that also does not work - it's in the Telephone number fields - it' supposed to check that the values entered are numbers. Would anyone be kind enough to try to run this page in your browser and see if the validation functions runs for you? If they don't, could you offer any suggestions as to code errors or possible browser settings that might be causing the problem? Thanks in advance to anyone offering their time!!! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="description" content="Page used to contact SRS" /> <meta name="keywords" content="resume, resumes, job, jobs, job market, job info, interview tips, job interview, salary, salaries, cover letter, cover letters, SRS, Superior Resume Source, business cards, help with resume, help with job search" /> <title>Contact SRS</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <script type="text/javascript">/* <![CDATA[ *//* ]]> */ function checkForNumber() { if (isNan(document.forms[0].area.value)){alert("You must enter a numerical value");return false;} else if (isNan(document.forms[0].exchange.value)){alert("You must enter a numerical value");return false;} else if (isNan(document.forms[0].phone.value)){alert("You must enter a numerical value");return false;} } // function validateForm () // { // if(document.forms[0].firstname.value==""){alert("You must enter your first name.");return false;}} // } // else if(document.forms[0].lastname.value== ""){alert("You must enter your last name.");return false;} // else if(document.forms[0].address1.value== ""){alert("You must enter your address.");return false;} // else if(document.forms[0].city.value== ""){alert("You must enter a city.");return false;} // else if(document.forms[0].state.value== ""){alert("You must enter a state.");return false;} // else if(document.forms[0].zip.value== ""){alert("You must enter your zip code.");return false;} // else if(document.forms[0].area.value== ""||document.forms[0].exchange.value== ""||document.forms[0].phone.value== "") // {alert("You must enter a complete phone number.");return false;}} // else {alert('Thank you! SRS will contact you within one business day.');}} function isEmpty(strfirst, strlast, straddress, strcity, strstate, varzip) { strfirst = document.forms[0].firstname.value strlast = document.forms[0].lastname.value straddress = document.forms[0].address1.value strcity = document.forms[0].city.value strstate = document.forms[0].state.value varzip = document.forms[0].zip.value //name field if (strfirst == "" || strlast == null || strfirst.charAt(0) == ' ') { alert("\"First Name\" is a mandatory field.\nPlease amend and retry.") return false; } //last name field if (strlast == "" || strlast == null || strlast.charAt(0) == ' ') { alert("\"Last Name\" is a mandatory field.\nPlease amend and retry.") return false; } //address field if (straddress == "" || straddress == null || straddress.charAt(0) == ' ') { alert("\"Address\" is a mandatory field.\nPlease amend and retry.") return false; } return true; } //city field if (strcity == "" || strcity == null || strcity.charAt(0) == ' ') { alert("\"City\" is a mandatory field.\nPlease amend and retry.") return false; } //state field if (strstate == "" || strstate == null || strstate.charAt(0) == ' ') { alert("\"State\" is a mandatory field.\nPlease amend and retry.") return false; } } function check(form)){ if (isEmpty(form.firstname)){ if (isEmpty(form.lastname)){ if (isEmpty(form.address1)){ if (isEmpty(form.city)){ if (isEmpty(form.state)){ } } } } } return false; } </script> </style> </head> <body> <a name="top"></a> <div id="container"> <div id="header"> <h1></h1> </div> <div id="content"> <h2>Contact SRS</h2> <p>Use this page to contact SRS and/or order products and services. Refer to our <a href="services.htm">Services</a> page for pricing.</p> <p><strong>Remember, our work is guaranteed or your money back!</strong></p> </div> <div id="sidebar"> <ul> <li><a href="index.htm">Home</a></li> <li><a href="about.htm">About SRS</a></li> <li><a href="services.htm">Services</a></li> <li><a href="contact.htm">Contact SRS</a></li> </ul> <div class="widget"> Did you know that employers prefer CV's that are limited to three pages or less? </div> <div class="widget"> First impressions last a lifetime... write a Thank You letter EVERY time! </div> <div class="widget"> Want to know your personality type? Take this FREE <a href="http://www.careerfulfillment.com/?hop=daviduk"> personality test.</a> </div> </div> </div> <form method="get" enctype="application/x-www-form-urlencoded"> <table border="0"> <tr> <td id="contact table" valign="top"> <h3><strong>Contact SRS</strong></h3> <p><strong>* Required</strong><p> <p>First Name*<br /> <input type="text" name="firstname" size="50" /> </p> <p>Last Name*<br /> <input type="text" name="laststname" size="50" /> </p> <p>Address*<br /> <input type="text" name="address1" size="50" /><br /> <input type="text" name="address2" size="50" /> </p> <p>City, State, Zip*<br /> <input type="text" name="city" size="34" /> <input type="text" name="state" size="2" maxlength="2" /> <input type="text" name="zip" size="10" maxlength="10" onchange="return checkForNumber;" /> </p> <p>Telephone*</p> <p>(<input type="text" name="area" size="3" maxlength="3" onchange="return checkForNumber;" />) <input type="text" name="exchange" size="3" maxlength="3" onchange="return checkForNumber;" /> <input type="text" name="phone" size="4" maxlength="4" onchange="return checkForNumber;" /></p> <strong>Check the reason(s) for your inquiry?*</strong> <p><input type="checkbox" name="geninquiry" value="General_Inquiry" />General Inquiry <br/> <input type="checkbox" name="help" value="Help" />Help<br/> <input type="checkbox" name="new_resume" value="Order New Resume" />Order a New Resume <br /> <input type="checkbox" name="Update_resume" value="Update My Resume" />Update My Resume <br/> <input type="checkbox" name="cover_letter" value="Order Cover Letter" />Order a Cover Letter <br /></p> <textarea rows="10" cols="50">Type your comments here</textarea> <p><input type="button" name="Submit" value="Submit" onsubmit="return check(this);" /> <input type="reset" /></p> </td> </tr> </table> </form> <a href="#top">Back to Top</a><br /> </body> </html> I need to input the functions for the buttons ( Push, Pop,Peek, Enqueue, and Dequeue) nothing I try works. Can anyone possible help me with one of the push, pop or peek, and then one of the Enqueue or Dequeue (any information I see online always has to do with wordpress which im not using) . Im really not asking for someone to do all the work for me, I just need a start. ok here is my code with the buttons just no functions <html> <head> <title>COP2500 - Lab 9</title> </style></head> <body> <center> <h3><b>COP2500 Assignment 9</b></h3> <b>Queue:</b> <form name="queue"> <input type=text size=60 name="display"><br> <input type=text size=5 name="entry"> <input type=button value="Enqueue" onClick="enqueue()"> <input type=button value="Dequeue" onClick="dequeue()"> </form> <hr> <b>Stack:</b> <form name="stack"> <table> <tr> <td>Entry: <input type=text size=5 name="entry"><br> <input type=button value="Push" onClick="push()"><br> <input type=button value="Pop" onClick="pop()"> <br> <input type=button value="Peek" onClick="peek()"><br> </td> <td><textarea name=display rows=20></textarea></td> </tr> </table> </form> </center> <script language="JavaScript"> var myqueue = new Array(); var front; var back; front = 0; back = -1; var mystack = new Array(); var top; top = -1; function enqueue() { // This function should take the value from the 'entry' text box and // add it to the back of the queue. The 'back' queue variable must be // incremented. // Since the queue changed, call the display function. Done. display_queue(); } function dequeue() { // This function should display the value of the 'front' element // in the queue using the 'alert' function and then increment the value // of the front variable. // if the queue is empty, i need to say so. // Since the queue changed, call the display function. Done. display_queue(); } function push() { // This function should add the value in the 'entry' text box to the stack, // and then increment the value of the 'top' variable. // Since the stack changed, call the display function. . display_stack(); } function pop() { // This function should use the alert function to display the top // of the stack and then remove the top item from the stack. // You can 'remove' the item simply by decrementing the value of 'top'. // If the stack is empty, it needs to say so. // Since the stack changed, call the display function. . display_stack(); } function peek() { // This function should use the 'alert' function to display the top // of the stack but not change the stack. If stack is empty,it needs to say so. } // ***************************************************************** // Do not edit anything below this line. Use the functions as given. // ***************************************************************** function display_queue() { var output; var i; output = " "; for (i = back; i >= front; i--) output = output + myqueue[i] + " "; document.queue.display.value = output; } function display_stack() { var output; var i; output=""; for (i = top; i > -1; i--) output = output + mystack[i] + "\n"; document.stack.display.value = output; } </script> </body> </html> im no jQuery rookie but for the first time ...instead of simply writing out the animation jQuery('element').hide() in that way.... i instead needed to keep track of the functions so i wrote it like function hidetheElement() { jQuery('element').hide() } but now i need to run 2 of those functions together after a click ...for example jQuery('ClickedElement').click( movethelement,hidethelement ) see what i mean?....i dont know how to properly run two defined functions whats the proper syntax.... and here is my actual code for reference (its basically a menu link being clicked...hiding one page...and showing another....i needed to define the functions so if a menu link is clicked it could hide every other page first...by function....and then call a function to show the page Code: jQuery(document).ready( function() { jQuery('#ladiesmenu').click( previewoff,ladieson ); function previewoff() { jQuery('#preview').fadeOut(500); } function ladieson() { jQuery('#ladies').fadeIn(500); } Code: <html> <head> <script> //declare variable //var temp = 0; var Num = parseInt(prompt('Enter an Intger')); // starts the function factorial factorial(Num); //The function is declared function factorial(currentNumber) { if(currentNumber > 1) { //temp = temp + (currentNumber); factorial(currentNumber - 1); alert(currentNumber); } else { alert("here"); } } </script> </head> <body> </body> </html> This code is suppose to take the prompt number and keep subtracting one if > 1 but it seems to be not doing that at all and doing the else statement first then + till it gets to the prompt number. I have been staring at it for a while now and cant work it out. Thanks . Why do we have functions without parentheses at times? Ex 1) http://www.youtube.com/watch?v=OHYFNDzlDTE (On 2:18) Ex 2) At the bottom: Code: var panel, flag; function mousemoveResponse(e) { var x, y; if( window.event ) { x= event.x; y=event.y; } else if(e) { x=e.pageX; y=e.pageY; } if(flag) { panel.innerHTML = "Mouse is at X: " + x + ", Y: " + y ; } } function mouseoverResponse() { flag = false; panel.innerHTML = "Mouse is Over"; } function mouseoutResponse() { flag = true ; } function init() { panel=document.getElementById("panel"); flag = true; panel.innerHTML="Move the mouse..." ; document.onmousemove=mousemoveResponse; panel.onmouseover=mouseoverResponse; panel.onmouseout=mouseoutResponse; } onload=init; Hello, I have a very large function that activates on one click. It does many individual events that modify my site. They all work seperately but when I put them in a single function they all break. Is there a way, order or priority for putting large things of code in functions? I tried doing {} blocks but it didn't help. I would like to start off by saying I know there isn't a sure fire, 100% way to tell if javascript is enabled on a users browser. Because of this, it's a good idea to check form input using a php (or another server-side language) function. Now, let's say the user DOES have javascript enabled. I would like to check that same form input with a javascript function, instead of a php function. How would I be able to do that? If both php and javascript functions are in the same script, how does the browser know which one to run and how can I make it run the javascript function if the user has javascript enabled? I'm tryingto make a button where, when you click the button, a variable will increase and refresh (reload the number displayed, but one number higher. Here is what I have: Code: <html> <head> </head> <body> <script type="text/javascript"> x=1 document.write(x) </script> <input type="button" value="Up" onclick="document.write (++ x) "> <input type="button" value="Down" onclick="document.write (-- x)"> <input type="button" value="Reload" onclick="history.go(0)"> </body> </html> The problem with this is: When you hit the "up" button, everything on the page dissapears and it just outputs "2". All the buttons and stuff dissapear? There must be a better way to do it. And would I need to use a database. Any help? Im having problems with this code working as it should. the top banner is supposed to cycle the second banner is supposed to be random the 3rd is a slide show that is supposed to work in order Everything works in random order. Any help would be appreciated. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>HTML and JavaScript</title> <script type="text/javascript"> var imgArray=new Array(4); imgArray[0]= new Image; imgArray[0].src="lions3.gif"; imgArray[1]= new Image; imgArray[1].src="tigers3.gif"; imgArray[2]= new Image; imgArray[2].src="bears3.gif"; imgArray[3]= new Image; imgArray[3].src="ohmy3.gif"; var index=0 function startup() { cycle(); select(); return } </script> <script type="text/javascript"> function cycle() { document.banner.src= imgArray[index].src; index++; if (index==4) { index=0; } setTimeout("cycle()",1000); return; } </script> <script type="text/javascript"> function select() { index=Math.floor(Math.random()*4); document.banner1.src=imgArray[index].src; setTimeout("select()",2000); return; } </script> <script type="text/javascript"> function doBack() { if (index>0) { index--; document.slideshow.src=imgArray[index].src; } return; } function doNext() { if (index<3) { index++; document.slideshow.src=imgArray[index].src; } return; } </script> </head> <body onload="startup()";> <center><img name="banner" src="lions3.gif" id="banner"> <div align="center"><img name="banner1" src="tigers3.gif" id="banner1"></div> </center> <div align="center"> <h2>My JavaScript Slideshow</h2> <p><img name="slideshow" src="lions3.gif"></p> <p><a href="javascript:doBack()">Back</a> * * * * <a href="javascript:doNext()">Next</a></p> </div> </body> </html> |