JavaScript - Creating A Slideshow Program
Hey everyone, I am writing a Javascript program which requires several different functions to be assigned to buttons, and an array created as the source of images in the program. I have written/looked at/worked on it for hours and hit a wall. Can't make heads or tails of it anymore, and I would really appreciate any insight on where to go or points of weakness in my code! If anyone is willing to help me out, let me know and I will post.
Again any help or knowledge would be MUCH appreciated! Similar TutorialsHi, I have to create a simple program in javascript (temperature converter) but without the use of functions. The other parameters in this are that: It creates a prompt asking the person if they want Fahrenheit -> Celsius or Celsius -> Fahrenheit It then has another prompt asking what temperature they'd like converted Finally, the output has both the original temperature and the converted one. Also it was noted that I had to use IF statement to guide the "flow of the program." I've been having a lot of troubles with it, as I do not know how to create a program without the use of functions. I'm also having issues with figuring out how to program it so the program knows that the user picked Fahrenheit to Celsius/Celsius to Fahrenheit and prompts them about the temperature they'd want changed. Any help/guiding would be great. Thanks. I would like to create a slideshow like what most wedding sites have but I would like to have some fancy transitions like "Random dissolve, checkerboard, spiral" e.t.c, how can I add any of those to my slideshow, this is a regular fade slideshow I have: Code: var speed=40; /* this is the image fade speed - higher value=slower, lower value=faster */ var timer=4000 /* this is the time that each image is static - 4000=4 seconds */ var pics=new Array(); pics[0]='images/autumn.jpg'; pics[1]='images/lace.jpg'; pics[2]='images/lotus1.jpg'; pics[3]='images/lotus.jpg'; pics[4]='images/apple.jpg'; pics[5]='images/apple4.jpg'; pics[6]='images/girl.jpg'; pics[7]='images/clouds.jpg'; pics[8]='images/blood.jpg'; pics[9]='images/buddha.jpg'; /****************** these links are optional and can be removed if not required ******************/ var links=new Array(); links[0]='http://www.google.com/'; links[1]='http://www.guardian.co.uk/crossword/'; links[2]='http://www.htmlforums.com/'; links[3]='http://www.w3schools.com/'; links[4]='http://www.alistapart.com/'; links[5]='http://news.bbc.co.uk/'; links[6]='http://validator.w3.org/'; links[7]='http://en.wikipedia.org/'; links[8]='http://tools.dynamicdrive.com/gradient/'; links[9]='http://www.hoogerbrugge.com/'; /*************************************************************************************************/ var topop=100; var botop=0; var topnum=0; var botnum=1; var test=0; function init() { objt=document.getElementById('top'); if(document.getElementById('link')) { objl=document.getElementById('link'); } else { objl=document.getElementById('container'); } bimg=document.createElement('img'); bimg.setAttribute('id','bot'); bimg.setAttribute('src',pics[1]); objl.appendChild(bimg); objb=document.getElementById('bot'); fader=setTimeout(function(){fadeout()},timer); } function fadeout() { if(document.getElementById('link')) { objl.href='#'; objl.style.cursor='default'; } test==0?(topop--,botop++):(topop++,botop--); if(objt.filters) { objt.style.filter='alpha(opacity='+topop+')'; objb.style.filter='alpha(opacity='+botop+')'; } else { objt.style.opacity=topop/100; objb.style.opacity=botop/100; } if(topop==0){ test=1; topnum+=2; if(topnum==pics.length+1) { topnum=1; } if(topnum==pics.length){ topnum=0; } objt.src=pics[topnum]; clearTimeout(fader); return stop(); } if(topop==100){ test=0; botnum+=2; if(botnum==pics.length) { botnum=0; } if(botnum==pics.length+1){ botnum=1; } objb.src=pics[botnum]; clearTimeout(fader); return stop(); } setTimeout(function(){fadeout()},speed); } function stop(){ if(document.getElementById('link')) { objl.style.cursor='pointer'; } if(test==0){ objl.href=links[topnum]; topop=100; botop=0; } if(test==1){ if(document.getElementById('link')) { objl.href=links[botnum]; } topop=1; botop=99; } setTimeout(function(){fadeout()},timer); } if(window.addEventListener){ window.addEventListener('load',init,false); } else { if(window.attachEvent){ window.attachEvent('onload',init); } } I've found many examples of creating slideshows using javascript all over the internet and these forums. However, I haven't found any that show how to create a slideshow and give each slide a different time interval between switching to the next one. I'm changing my website over from a Flash based one to something that can be read on all devices. In doing so I've looked for ways to add a little motion to the site. I'm working with a friend who has been doing most of the site but here and there I like to get my hands dirty and try some things on my own. Unfortunately he doesn't know Javascript. I wanted to have an animation window in the bottom corner of the page. Look at http://www.whyreboot.com/blog to see what I came up with. I took a slider plugin for Wordpress and basically created a bunch of slides and entered them in to switch every .5s so that I could change how quickly they changed images by making some of them repeat the same slide 4 times for 2s, 2 times for 1s, etc. Though it's not pretty, it works. On Firefox everything looks great although it'd be nice to have fade in and out on each slide. On an iPad or IE it actually shows the flash between slides even when they're the same image. Quite frankly, it's ugly. Does anybody have any ideas? Please keep in mind that I am a network systems engineer by trade so the only coding I know is Cisco IOS, etc. I'm trying to get this to work in a Wordpress site on a window with dimensions of 450X230. I apologize if this is not the correct place to look for help on this. I have read the forum fules and guidelines and this seemed to be the right place. Thanks ahead of time for any sage advice from what looks like a great community of web geeks! I am looking for tutorials on creating a slideshow with thumbnails, but i need one where i can put the mouse over the thumbnail depending on the direction i am the mouse the thumbnail will move left or right thanks I need a count down clock that will count down 18 minutes and reset itself at the end. also i need a counter that increases by +1 every 18 minutes starting at 0. thankyou This is my code from prelim to finals. The missing part here is when the input is less than or equal to 65 and greater than 100, the prompt will say INVALID ENTRY. However, after it says Invalid Entry, it must ask you to enter again an Entry until you input a valid entry. It must be terminated after you input from prelim to finals either 0,20,30,40 or after you input a valid entry and after the program calculated it. My program does not terminate after I input valid entries. It just continue to ask grade again and again even it already calculated the grades. I don't know how will I put those code inside the program. I'm getting really confused. Code: <html> <head> <title>Web Programming Laboratory Exam</title> </head> <body> <script language="JavaScript"> do { { var pg=prompt('Enter Prelim Grade','0'); if(pg==0) { alert('No Grade'); document.write('<br>Prelim Grade is '+pg); } else if(pg==20) { alert('Not Attending'); document.write('<br>Prelim Grade is '+pg); } else if(pg==30) { alert('Dropped'); document.write('<br>Prelim Grade is '+pg); } else if(pg==40) { alert('Incomplete'); document.write('<br>Prelim Grade is '+pg); } else document.write('Prelim Grade is '+pg); var mg=prompt('Enter Midterm Grade','0'); } { if(mg==0) { alert('No Grade'); document.write('<br>Midterm Grade is '+mg); } else if(mg==20) { alert('Not Attending'); document.write('<br>Midterm Grade is '+mg); } else if(mg==30) { alert('Dropped'); document.write('<br>Midterm Grade is '+mg); } else if(mg==40) { alert('Incomplete'); document.write('<br>Midterm Grade is '+mg); } else document.write('</br>Midterm Grade is '+mg); var fg=prompt('Enter Final Grade','0'); } { if(fg==0) { alert('No Grade'); document.write('<br>Final Grade is '+fg); } else if(fg==20) { alert('Not Attending'); document.write('<br>Final Grade is '+fg); } else if(fg==30) { alert('Dropped'); document.write('<br>Final Grade is '+fg); } else if(fg==40) { alert('Incomplete'); document.write('<br>Final Grade is '+fg); } else { document.write('</br>Final Grade is '+fg); sg=((pg*.3)+(mg*.3)+(fg*.4)); document.write('<br>Your Semestral Grade is '+sg); } } if (sg>=74.5) { document.write('<br>Remarks: Passed'); document.write('</br>This Program is developed by -k3nN'); } else if (sg<74.5) { document.write('<br>Remarks:Failed'); document.write('</br>This Program is developed by -k3nN'); } } while (sg>=74.5|sg<74.5) { document.write('</br>Thanks') } </script> </body> </html> I have an assignment to create a program in JS but I have not read JS much more. So, for this assignment, can anyone help me to solve this assignment? Check attachment. Uploaded with ImageShack.us Hello everyone. This is my first program. According to the idea of a program that calculates the sum of savings with the bank interest rates that is paid each year. And I put one amount every month. The question is very simple why full = 0? Code: var years = prompt("How many years will accumulate?)"); var prec = prompt("And how many % bank give?"); var income = prompt("How many you will put off in bank?"); var num = 12; var full = 0; months=years*num; console.log("Altogether we get " + years + " years and " + months + " months.") for (var month = 0; month == months; month++) { if (month % num == 0) { full = full + income + (full*prec/100); } else { full = full + income; } } console.log("Total accumulated =" + full); Reply With Quote 01-24-2015, 04:37 PM #2 leonfresh View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 8 Thanks 0 Thanked 0 Times in 0 Posts var full = 0 declares the variable as an integer variable. it's important to do so to avoid declaration errors. Reply With Quote 01-24-2015, 05:09 PM #3 jmrker View Profile View Forum Posts Senior Coder Join Date Aug 2006 Location FL Posts 3,175 Thanks 39 Thanked 510 Times in 504 Posts You have a logic problem. Try... Code: for (var month = 0; month<months; month++) { Also note that your logic applies the full percentage at the 1st month of the loan/deposit. Is this what your really intended? Reply With Quote Users who have thanked jmrker for this post: Nadir+ (01-24-2015) 01-24-2015, 06:28 PM #4 Nadir+ View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 6 Thanks 1 Thanked 0 Times in 0 Posts i catch another problem, when i change this Code: for (var month = 0; month == months; month++) { on this, Code: for (var month = 0; month<months; month++) { program started work. But in rusults see this . Code: Altogether we get 1 years and 12 months. Total accumulated =01000100100100100100100100100100100100 all code there Code: var years = prompt("How many years will accumulate?)"); var prec = prompt("And how many % bank give?"); var income = prompt("How many you will put off in bank?"); var num = 12; var full = 0; months=years*num; console.log("Altogether we get " + years + " years and " + months + " months.") for (var month = 0; month < months; month++) { if (month % num == 0) { full = full + income + (full*prec/100); } else { full = full + income; } } console.log("Total accumulated =" + full); Reply With Quote 01-24-2015, 06:39 PM #5 Nadir+ View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 6 Thanks 1 Thanked 0 Times in 0 Posts i realized something if i delete var income and just put in its place 100, program work almost normal. Code: Altogether we get 2 years and 24 months. main.js:17 Total accumulated =2520 But if i write 1 year it dont work,how can i fix it? Code: Altogether we get 1 years and 12 months. main.js:17 Total accumulated =1200 Reply With Quote 01-24-2015, 09:42 PM #6 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts The value you get from a call to prompt() is *ALWAYS* a string. When you use the + operator with a string, it does *NOT* do addition; it does string concatenation. You just need to convert all those prompt() results to numbers: Code: var years = Number( prompt("How many years will accumulate?") ); var prec = Number( prompt("And how many % bank give?") ); var income = Number( prompt("How many you will put off in bank?") ); Also, you need to do Code: for (var month = 0; month <= months; month++) { else you will only do (for example) up to month 23 when the user asks for 2 years. Be aware that prompt() and confirm() and console.log() are considered VERY obsolete and should only be used for debugging purposes, not for real web code. I'm very new at Javascript and writing programs so I'm not sure if this is even possible to do. I want to write a program that allows someone to select four tasks from a dropdown menu. The tasks are each 1 hour long. I want the program to calculate the number of hours and display that information below the tasks. I also want the person to be able to add or remove tasks. I get how to save tasks and display the results but I don't know how to calcuate the number of hours. Any suggestions? Here is what I have so far: Code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Four Tasks</title> <style> body { background-color:silver; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; } h1 { font-family:Arial, Helvetica, sans-serif; font-size:1.4em; } </style> <script> function storeTask(task) { var taskDetail = document.getElementById(task).value; localStorage.setItem(task, taskDetail); } function getTask(task) { document.getElementById(task).value = localStorage.getItem(task); } function clearTask(task) { localStorage.removeItem(task); document.getElementById(task).value=""; } function displayTasks() { outputResults = document.getElementById("Results"); outputResults.innerHTML = 'Task 1: ' + localStorage.getItem('task1') + '<br />' + 'Task 2: ' + localStorage.getItem('task2') + '<br />' + 'Task 3: ' + localStorage.getItem('task3') + '<br />' + 'Task 4: ' + localStorage.getItem('task4') + '<br />' + ''; } </script> </head> <body> <table width="100%"> <tr> <td valign="top"> <div id="outer"> <h1>Four Tasks</h1> My To Do List: <br><br> Task 1: <select id="task1"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task1');"> <input type="button" value="Clear" onclick="clearTask('task1');"> <br><br> Task 2: <select id="task2"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task2');"> <input type="button" value="Clear" onclick="clearTask('task2');"> <br><br> Task 3: <select id="task3"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task3');"> <input type="button" value="Clear" onclick="clearTask('task3');"> <br><br> Task 4: <select id="task4"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task4');"> <input type="button" value="Clear" onclick="clearTask('task4');"> </div> </td> <td valign="top"> My Tasks: <br> <input type="button" value="Display tasks" onclick="displayTasks();"> <div id="Results"></div> </td> </tr> </table> </body> </html> Im writing this code for a gas station program. I have been writing and improving my code for about 3 weeks now and its quite long. I have about classes , customer class, office class and a gas pumps classes. I need help on how to get started on finding the total output at the end of the day. Conceptually i know what i have to do but I don't know where to begin writing the code. I think each time there is a new customer i should add the amount of fuel purchased to a new total fuel purchases variable in the gas pump class. If any one could give me some advice or tips on my theory it would be great ! Should I create a method or can i be done without one. Code: import java.util.Random; import java.util.Scanner; public class Customer { private String carTag; private double gasPurchased; private int gasType; public Customer () { Random gen = new Random ( ); carTag = ""; for (int i = 1; i <= 6; i++) { //a random number between 48 and 90 int code = gen.nextInt (43)+ 48; if ((code <= 64) && (code >= 58)) { i--; continue; } carTag += ((char)(code)); } System.out.println ("a car arrives; tag number:" + carTag); } public int getGasType () { Scanner inputDevice = new Scanner (System.in); //1:regular, 2:plus, 3:premium System.out.println ("enter type of gas to buy " + "(1:regular, 2:plus, 3:premium): "); gasType = inputDevice.nextInt (); return gasType; } public double getGasPurchased () { Random gen = new Random (); gasPurchased = gen.nextDouble ()* 50; return gasPurchased; } public String getCarTag () { return carTag; } Code: import java.util.Random; public class Office { public static void main (String [ ] args) { double regularTank = 1000; double plusTank = 1000; double primiumTank = 1000; GasPump pump1 = new GasPump ( ); GasPump2 pump2 = new GasPump2 ( ); Random gen = new Random (); //asuumint gas tanks always have gas, will upgrade later do { int whatHappens = gen.nextInt (100); if (whatHappens == 5) { System.out.println ("gas station closed"); break; } else if ((whatHappens % 10) == 0) { if (pump1.pumpAvailable ()) pump1.customerArrival (); else System.out.println ("a new customer arrives at pump 1, but is turned away, gas pump is busy"); } else { if (pump1.pumpAvailable ()) System.out.println ("no customer; waiting........."); } if (!pump1.pumpAvailable()) { if (pump1.updateClock () == 0) pump1.saleComplete (); } } while (true); do system.exit () Code: public class GasPump { final private double REGULAR_PRICE = 3.15; final private double PLUS_PRICE = 3.5; final private double PREMIUM_PRICE = 4.5; final private double HOSE_FLOW_RATE = 0.85; private double totalPayment; private Customer who; private int timeLeftToFinish; private int gasType; private double gasPurchased; private String carTag; public GasPump () { who = null; totalPayment = 0; timeLeftToFinish = 0; } public void customerArrival () { who = new Customer (); System.out.println ("welcome to jack's gas station PUMP 1 "); gasType = who.getGasType (); gasPurchased = who.getGasPurchased (); timeLeftToFinish = (int)(gasPurchased/HOSE_FLOW_RATE); System.out.println (timeLeftToFinish + " total time units needed for this transaction..."); carTag = who.getCarTag (); } private void printReceipt ( ) { System.out.println ("****Sale Receipt"); switch (gasType) { case 1: System.out.println ("regular gas"); break; case 2: System.out.println ("plus gas"); break; case 3: System.out.println ("premium gas"); break; } System.out.println ("gas amount: " + gasPurchased + "\ntotal payment" + totalPayment + "\nthank you"); System.out.println("Pump has " + regularTank()); } private void resetPump ( ) { who = null; totalPayment = 0; timeLeftToFinish = 0; } public int updateClock () { timeLeftToFinish--; System.out.println (timeLeftToFinish + " time units left to finish "); return timeLeftToFinish; } public void saleComplete ( ) { switch (gasType) { case 1: totalPayment = REGULAR_PRICE * gasPurchased; break; case 2: totalPayment = PLUS_PRICE * gasPurchased; break; case 3: totalPayment = PREMIUM_PRICE * gasPurchased; break; } printReceipt ( ); resetPump ( ); } public boolean pumpAvailable () { return (who == null); } } <script type="text/javascript"> var myString = "zero one two three four"; var mySplitResult = myString.split(" "); for(i = 0; i < mySplitResult.length; i++){ document.write("<br /> Element " + i + " = " + mySplitResult[i]); } </script> "split" function splits the string whenever it encounters "space". But please explain me how the strings are stored in "mySplitResult". And can we use Arrays for this program? If so, can you code it. Thanks in advance! Basically i have an image of a ball that i am trying to make bounce from top to bottom so far it is just going to the bottom and stopping plz help thanks <head> <title></title> </head> <body> <center> <input type="button" value="Click" onClick="moveDown()"/> </center> <img id="Ball" src="ball.jpg" style="position:absolute; top:100px; left:100px;"/> <script language="JavaScript"> var Image = document.getElementById("Ball"); var Position = 100; var direction = 1; function moveDown() { if(direction > 0) { Image.style.top = parseInt(Image.style.top) + 20+'px'; } if(parseInt(Image.style.top)> 100 || direction > 1 ) direction = 1 if(parseInt(Image.style.top)> 500 || direction < 1 ) { direction = -1 Image.style.top = parseInt(Image.style.top) - 20+'px'; } } setInterval ("moveDown()", 50 ); </script> </body> </html> im looking to make a program for my site to where somebody can type something in and it will go onto a image like a userbar and then they can save that image with the txt the choose to go over it, does anybody have any advice for me to use? For class NumericQuestion Add setAnswer, a method that takes a double as input, converts it to a string and calls setAnswer in the superclass Question to store the answer. o Add checkAnswer, a method that takes an answer in string form, converts it to a double, gets the correct answer in string form from Question, converts it to a double, and returns true if they are within 0.01 of each other and false otherwise. For class quiz Change main so that all three questions are asked. presentQuestion that prints out the correct answer, only when the answer is wrong public class NumericQuestion { private String text; private Double answer; /** * Constructs a question with empty question and answer. */ public NumericQuestion() { text = ""; answer = 3.1416; } /** * Sets the question text. * @param questionText the text of this question */ public void setText(String questionText) { text = questionText; } /** * Sets the answer for this question. * @param correctResponse the answer */ public void setAnswer(Double correctResponse) { answer = correctResponse; } /** * Checks a given response for correctness. * @param response the response to check * @return true if the response was correct, false otherwise */ public boolean checkAnswer(String response) { return response.equals(answer); } /** * Displays this question. */ public void display() { System.out.println(text); } } import java.util.Scanner; public class Quiz { public static void main(String[] args) { Question first = new Question(); first.setText("What inherits data and behavior from a superclass?"); first.setAnswer("subclass"); ChoiceQuestion second = new ChoiceQuestion(); second.setText("Which modifies the object on which it operates in some way?"); second.addChoice("Accessor", false); second.addChoice("Mutator", true); second.addChoice("Method", false); second.addChoice("Variable", false); NumericQuestion third = new NumericQuestion(); third.setText("What is the numeric value for PI?"); third.setAnswer(3.1416); presentQuestion(first); presentQuestion(second); //presentQuestion(third); } /** Presents a question to the user and checks the response. @param q the question */ public static void presentQuestion(Question q) { q.display(); System.out.print("Your answer: "); Scanner in = new Scanner(System.in); String response = in.nextLine(); System.out.println(q.checkAnswer(response)); } } Hello people CF, I need some help with this Javascipt program that im trying to make. Ill provide you with the algorithm i have made and the javascript code. I only know basic javascripting and i had a lot of help with this. I need help getting the javascript code for comparing last date modified, renaming the copied file with last date modified, also i can get it to copy 1 file, but i need it to loop through all the files in the given folder. Algorithm Code: // get source and destination folder path // check if folder exists // if source folder exists, continue with the process, otherwise display an error message // if destination folder exists, proceed with transferring the files // get the file collections in the source folder // loop through each file to check if the file has been modified // if the file exists, check file attributes to the source file; 32 means file has changed // if file has changed, // compare the last date modified of the source and destination file // if the source last date modified is greater than the destination last date modified then // rename the destination file by appending the last date modified // to its file name and then transfer the lastest file from the source folder // otherwise, no need to copy the file and move to the next file // otherwise, do nothing and move on to the next file // otherwise, create a folder first before proceeding with transferring the files I had a lot of help with this Code: <HTML> <HEAD> <TITLE>FileSystem Object Demo</TITLE> <SCRIPT> Language = "JavaScript"> <!--hide from old browsers function checkExistingFolder(folder) { var FS = new ActiveXObject("Scripting.FileSystemObject"); return FS.FolderExists(folder); } function createFolder(folder) { var FS = new ActiveXObject("Scripting.FileSystemObject"); FS.createFolder(folder); document.write ("<BR>New folder created."); } function copyFile(source, dest) { var FS = new ActiveXObject("Scripting.FileSystemObject"); FS.copyFile(source + "\\Test.txt", dest + "\\Test.txt"); document.write ("<BR>File Copied."); } function runProgram () { var from = document.getElementById('from').value; var to = document.getElementById('to').value; var isExist = checkExistingFolder(to); alert(isExist); if(isExist) document.write("Folder Exists, checking last date modified........"); else { document.write("Folder doesn't exist."); createFolder(to); } copyFile(from, to); } // --> </SCRIPT> </HEAD> <BODY background="1330843076080.jpg"> <CENTER> <H1>FileSystem Object Demo</H1> FROM: <input type="text" id="from" value=""/> TO: <input type="text" id="to" value="d:\\test"/> <input type="button" onClick="runProgram()" value="Transfer Files"/> <SCRIPT LANGUAGE = "JavaScript"> <!--hide from old browsers // --> </SCRIPT> </CENTER> </BODY> </HTML> Im trying to write a program that determines if an array is Ragged or not. I'm fairly new to writing programs in javascript and need a little help with this program. So far I have the following and need to write the program aspect for it. Thanks for taking a look for me. Code: document.writenln("Ragged or not<br />") if (raggedOr(a)) document.writenln("Array is Ragged"); else document.writenln("Array is not Ragged"); raggedOr was going to be the name of the function. I wrote about this script a couple weeks ago. I stopped working on it, and just got on it today. Question, what's the easiest way to have it so Monday, tuesday, Wednesday, etc and then the total amount of hours gets added. Code: <html> <head> <script language="JavaScript" src="gen_validatorv5-.js" type="text/javascript" xml:space="preserve"></script> <script type="text/javascript"> function calc(nForm){ var inHour =parseInt( nForm.inHr.value) var inMinutes = parseInt( nForm.inMin.value); var lunchOutHour = parseInt(nForm.lunchOutHr.value); var lunchOutMinutes = parseInt( nForm.lunchOutMin.value); var lunchInHour = parseInt( nForm.lunchInHr.value); var lunchInMinutes = parseInt( nForm.lunchInMin.value); var outHour = parseInt( nForm.outHr.value); var outMinutes = parseInt( nForm.outMin.value); var linearInTime = 60*(inHour)+(inMinutes); var linearLunchOutTime = 60*(lunchOutHour)+(lunchOutMinutes); var linearLunchInTime = 60*(lunchInHour)+(lunchInMinutes); var linearOutTime = 60*(outHour)+(outMinutes); var workDay = linearOutTime-linearInTime; var lunchPeriod = linearLunchInTime-linearLunchOutTime; var linearMinutesWorked = workDay-lunchPeriod; var hoursWorked = parseInt(linearMinutesWorked/60); var minutesWorked = linearMinutesWorked-(hoursWorked*60) if (hoursWorked < 10){hoursWorked = "0"+hoursWorked} if (minutesWorked < 10){minutesWorked = "0"+minutesWorked} nForm.timeWorked.value = hoursWorked+":"+minutesWorked; } </script> </head> <body> <div align="center"> <h1> <script src='scripts/gen_validatorv5.js' type='text/javascript'></script> <script src='scripts/sfm_moveable_popup.js' type='text/javascript'></script> <style type='text/css'> .error_strings { font-family:Verdana; font-size:10px; color:#660000; } .sfm_float_error_box { position:absolute; z-index:999; cursor:default; font-family:Verdana; font-size:10px; color:#660000; background-color:#ffff66; border-style:solid; border-width:1px; border-color:#660000; } .sfm_float_box_td { padding:3px; cursor:default; font-family:Verdana; font-size:10px; color:#660000; background-color:#ffff66; } .sfm_close_box { font-family:Verdana; font-size:10px; font-weight:bold; color:#ffffff; background-color:#660000; border-width:0px; text-align:center; } .sfm_cr_box { font-family:Verdana; font-size:10px; color:#888888; border-style:solid; border-width:0px; border-color:#660000; } .sfm_cr_box a { color:#888888; } </style> Masquerade Timesheet Entry</h1> </div> <div id='timeSheet_errorloc' class='error_strings' style=''></div> <form name='timeSheet'> <table width="833" height="244" border="1" align="center"> <tr> <td width="266"><p align="left">Monday :</p> Clock In: <label> <input name="inHr" type="text" id="inHr" size="10" maxlength="2"> </label>   <label> <input name="inMin" type="text" id="inMin" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr" type="text" id="lunchOutHr" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin" type="text" id="lunchOutMin" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr" type="text" id="lunchInHr" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin" type="text" id="lunchInMin" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr" type="text" id="outHr" size="10" maxlength="2"> </label>   <label> <input name="outMin" type="text" id="outMin" size="10" maxlength="2"> </label> <p>Time Worked: <input type='text' name='timeWorked' size='5' readonly> </p></td> <td width="269"><p>Tuesday:</p> <p>Clock In: <label> <input name="inHr2" type="text" id="inHr2" size="10" maxlength="2"> </label>   <label> <input name="inMin2" type="text" id="inMin2" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr2" type="text" id="lunchOutHr2" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin2" type="text" id="lunchOutMin2" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr2" type="text" id="lunchInHr2" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin2" type="text" id="lunchInMin2" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr2" type="text" id="outHr2" size="10" maxlength="2"> </label>   <label> <input name="outMin2" type="text" id="outMin2" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked2' size='5' readonly> </p></td> <td width="276"><p>Wednesday:</p> <p>Clock In: <label> <input name="inHr3" type="text" id="inHr3" size="10" maxlength="2"> </label>   <label> <input name="inMin3" type="text" id="inMin3" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr3" type="text" id="lunchOutHr3" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin3" type="text" id="lunchOutMin3" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr3" type="text" id="lunchInHr3" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin3" type="text" id="lunchInMin3" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr3" type="text" id="outHr3" size="10" maxlength="2"> </label>   <label> <input name="outMin3" type="text" id="outMin3" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked3' size='5' readonly> </p></td> </tr> <tr> <td><p>Thursday:</p> <p>Clock In: <label> <input name="inHr4" type="text" id="inHr4" size="10" maxlength="2"> </label>   <label> <input name="inMin4" type="text" id="inMin4" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr4" type="text" id="lunchOutHr4" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin4" type="text" id="lunchOutMin4" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr4" type="text" id="lunchInHr4" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin4" type="text" id="lunchInMin4" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr4" type="text" id="outHr4" size="10" maxlength="2"> </label>   <label> <input name="outMin4" type="text" id="outMin4" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked4' size='5' readonly> </p></td> <td><p>Friday:</p> <p>Clock In: <label> <input name="inHr5" type="text" id="inHr5" size="10" maxlength="2"> </label>   <label> <input name="inMin5" type="text" id="inMin5" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr5" type="text" id="lunchOutHr5" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin5" type="text" id="lunchOutMin5" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr5" type="text" id="lunchInHr5" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin5" type="text" id="lunchInMin5" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr5" type="text" id="outHr5" size="10" maxlength="2"> </label>   <label> <input name="outMin5" type="text" id="outMin5" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked5' size='5' readonly> </p></td> <td><div align="left"> <p> <input type='button' value="Calculate" onClick="calc(this.form)"> <input type="button" name="reset_form" value="Clear Forms" onClick="this.form.reset();"> </p> <p>Total Time Worked: <input type="text" name="totalhr" id="totalhr"> </p> <label></label> </div></td> </tr> </table> <p align="left"> </P> <p align="left"> </P> <p align="left"> </P> <p align="left"> </P> <p><br> <br> <br> <br> </p> </form ><p> </p> <p> </p> </body> </html> I am 98% done with the Codecademy JS curriculum but I am stuck on this program. Can anyone see the problem? Code: var cashRegister = { total:0, //Dont forget to add your property lastTransactionAmount: 0; add: function(itemCost) { this.total += itemCost; this.lastTransactionAmount = itemCost; }, scan: function(item,quantity) { switch (item) { case "eggs": this.add(0.98 * quantity); break; case "milk": this.add(1.23 * quantity); break; case "magazine": this.add(4.99 * quantity); break; case "chocolate": this.add(0.45 * quantity); break; } return true; }, //Add the voidLastTransaction Method here voidLastTransaction: function(){ this.total -= this.lastTransactionAmount; }, }; cashRegister.scan('eggs',1); cashRegister.scan('milk',1); cashRegister.scan('magazine',1); cashRegister.scan('chocolate',4); //Void the last transaction and then add 3 instead cashRegister.voidLastTransaction(); cashRegister.scan('chocolate',3); //Show the total bill console.log('Your bill is '+cashRegister.total); Hello I am trying to send some values in combobox2 depending on one value selected in combobox1. Both are in php. Following is the code for combobox1 - Code: <td><div id="Gen_Core"> <?php $sql="SELECT t.Main_CoNo, t.Main_CoName FROM Main_Course t WHERE t.Modl_No ='2' and t.Main_CoName NOT IN (SELECT t1.Course_Name from Course t1 where t.Modl_No = t1.Module_ID and Student_ID='$Stud_ID')"; $result=mysql_query($sql); $options=""; while (@$row=mysql_fetch_array($result)) { $id=$row["Main_CoNo"]; $name=$row["Main_CoName"]; $options.="<OPTION VALUE=\"$id\">".$name.'</option>'; } ?><select size="4" style="width:100px; font-size: 10px;" name="classes[]" id="class_list" onClick="return validateForm()"><?=$options?></select></div></td> Here is Javascript program - <script type="text/javascript"> function validateForm() { var gen=document.forms["select"]["classes"].value; alert("hi"); } </script> If I select one value from this combobox1, I want to send that value to java script program which is not working...It is not going to Javascript program at all.. I tried couple of things like onClick, onSubmit in form, in select etc. But it seems nothing is working... What I want is - If one option is selected from combobox1, then javascript program should recognize it and send values for combobox2. How will I do it? Really confused..... what does this code mean "obj.to"? The code is here - Code: clearTimeout( obj.to ); I just want to know what does "to" mean here? |