JavaScript - Please Help Homework Code
I have a homework page with three schools , four classes, and 4 weeks. Thing is I can't get the assignments to come up in the assignments text area. I can if I only have two if...else conditions, and I have tried three with nesting, but it always comes up undefined. This is for a class assignment but I really need help. I commented out the codes that didn't work. Sometimes i didn't finish the whole code before testing so is that maybe why it didn't work? Must it be complete to work? Thanks in advance for any help.
I put the whole page in. I am very new to this, and i just can't get my head around it, so any help would be apreciated. It worked if all assignments as long as the assignments were the same for each class of each school. Daisey Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>functions</title> <script language="javascript"> function test2(form){ /*create a variable*/ var varSchool = form.ddlSchool.value var varClass = form.ddlClass.value var varWeek = form.ddlWeek.value var varResults /*create an if statement to determine school*/ if (varSchool==0){ varSchool = "Prairie High School's "; } else if (varSchool==1){ varSchool = "Prairie Middle School's "; } else if (varSchool==2){ varSchool = "Prairie Elementary School's "; } if (varSchool==0) { if ((varClass==0) && (varWeek==0)){ varResults = "000 this code works"; }else if ((varClass==0) && (varWeek==1)){ varResults = "001 this code works"; }else if ((varClass==0) && (varWeek==2)){ varResults = "002 this code works"; }else if ((varClass==0) && (varWeek==3)){ varResults = "003 this code works"; }else if ((varClass==1) && (varWeek==0)){ varResults = "010 this code works"; }else if ((varClass==1) && (varWeek==1)){ varResults = "011 this code works"; }else if ((varClass==1) && (varWeek==2)){ varResults = "012 this code works"; }else if ((varClass==1) && (varWeek==3)){ varResults = "013 this code works"; }else if ((varClass==2) && (varWeek==0)){ varResults = "020 this code works"; }else if ((varClass==2) && (varWeek==1)){ varResults = "021 this code works"; }else if ((varClass==2) && (varWeek==2)){ varResults = "022 this code works"; }else if ((varClass==2) && (varWeek==3)){ varResults = "023 this code works"; }else if ((varClass==3) && (varWeek==0)){ varResults = "030 this code works"; }else if ((varClass==3) && (varWeek==1)){ varResults = "031 this code works"; }else if ((varClass==3) && (varWeek==2)){ varResults = "032 this code works"; }else if ((varClass==3) && (varWeek==3)){ varResults = "033 this code works"; } } else if (varSchool==1) { if ((varClass==0) && (varWeek==0)){ varResults = "100 this code works"; }else if ((varClass==0) && (varWeek==1)){ varResults = "101 this code works"; }else if ((varClass==0) && (varWeek==2)){ varResults = "102 this code works"; }else if ((varClass==0) && (varWeek==3)){ varResults = "103 this code works"; }else if ((varClass==1) && (varWeek==0)){ varResults = "110 this code works"; }else if ((varClass==1) && (varWeek==1)){ varResults = "111 this code works"; }else if ((varClass==1) && (varWeek==2)){ varResults = "112 this code works"; }else if ((varClass==1) && (varWeek==3)){ varResults = "113 this code works"; }else if ((varClass==2) && (varWeek==0)){ varResults = "120 this code works"; }else if ((varClass==2) && (varWeek==1)){ varResults = "121 this code works"; }else if ((varClass==2) && (varWeek==2)){ varResults = "122 this code works"; }else if ((varClass==2) && (varWeek==3)){ varResults = "123 this code works"; }else if ((varClass==3) && (varWeek==0)){ varResults = "130 this code works"; }else if ((varClass==3) && (varWeek==1)){ varResults = "131 this code works"; }else if ((varClass==3) && (varWeek==2)){ varResults = "132 this code works"; }else if ((varClass==3) && (varWeek==3)){ varResults = "133 this code works"; } } else (varSchool==2) { if ((varClass==0) && (varWeek==0)){ varResults = "200 this code works"; }else if ((varClass==0) && (varWeek==1)){ varResults = "201 this code works"; }else if ((varClass==0) && (varWeek==2)){ varResults = "202 this code works"; }else if ((varClass==0) && (varWeek==3)){ varResults = "203 this code works"; }else if ((varClass==1) && (varWeek==0)){ varResults = "210 this code works"; }else if ((varClass==1) && (varWeek==1)){ varResults = "211 this code works"; }else if ((varClass==1) && (varWeek==2)){ varResults = "212 this code works"; }else if ((varClass==1) && (varWeek==3)){ varResults = "213 this code works"; }else if ((varClass==2) && (varWeek==0)){ varResults = "220 this code works"; }else if ((varClass==2) && (varWeek==1)){ varResults = "221 this code works"; }else if ((varClass==2) && (varWeek==2)){ varResults = "222 this code works"; }else if ((varClass==2) && (varWeek==3)){ varResults = "223 this code works"; }else if ((varClass==3) && (varWeek==0)){ varResults = "230 this code works"; }else if ((varClass==3) && (varWeek==1)){ varResults = "231 this code works"; }else if ((varClass==3) && (varWeek==2)){ varResults = "232 this code works"; }else if ((varClass==3) && (varWeek==3)){ varResults = "233 this code works"; } } /* make a conditional assignment variable with two conditions class and week*/ /*var varscClass if ((varSchool == 0) && (varClass == 0)){ varscClass == 0 }else if ((varSchool == 0) && (varClass == 1)){ varscClass == 1 }else if ((varSchool == 0) && (varClass == 2)){ varscClass == 2 }else if ((varSchool == 0) && (varClass == 3)){ varscClass == 3 }else if ((varSchool == 1) && (varClass == 0)){ varscClass == 4 }else if ((varSchool == 1) && (varClass == 1)){ varscClass == 5 }else if ((varSchool == 1) && (varClass == 2)){ varscClass == 6 }else if ((varSchool == 1) && (varClass == 3)){ varscClass == 7 }else if ((varSchool == 2) && ( varClass == 0)){ varscClass == 8 }else if ((varSchool == 2) && ( varClass == 1)){ varscClass == 9 }else if ((varSchool == 2) && ( varClass == 2)){ varscClass == 10 }else if ((varSchool == 2) && ( varClass == 3)){ varscClass == 11 }*/ /*if ((varscClass == 0) && (varWeek == 0)){ classWeekassign = "week 1 of reading is read Chapter 1." }else if ((varscClass == 0) && (varWeek == 1)){ classWeekassign = "week 2 of reading is complete the Chapter 1 Review, page 20." }else if ((varscClass == 0) && (varWeek == 2)){ classWeekassign = "week 3 of reading is read Chapter 2." }else if ((varscClass == 0) && (varWeek == 3)){ classWeekassign = "week 4 of reading is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 0)){ classWeekassign = "week 1 of math is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 1)){ classWeekassign = "week 2 of math is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 2)){ classWeekassign = "week 3 of math is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 3)){ classWeekassign = "week 4 of math is complete the Chapter 3 Review, page 40." }*/ /*do a switch to determine favorite color*/ switch(varClass){ case "0": varResults = varSchool + "reading assignment for "; break; case "1": varResults = varSchool + "math assignment for "; break; case "2": varResults = varSchool + "science assignment for "; break; case "3": varResults = varSchool + "english assignment for "; } var classWeekassign /*another attempt failed if (varSchool==0) { if (varClass==0) { if (varWeek==0){ classWeekassign = "week 1 is to read Chapter 1." } else if(varWeek!=0){ } } else if((varClass==0) && (varWeek==1)){ classWeekassign = "week 1 of reading is do the Chapter 1 Review, page 20." } else if((varClass==0) && (varWeek==2)){ classWeekassign = "week 3 of reading is read Chapter 2." } else if((varClass==0) && (varWeek==3)){ classWeekassign = "week 4 of reading is do the Chapter 2 Review, page 40." } } else if(varSchool==1){ } */ /*Concatenate a string*/ varResults = varResults + classWeekassign; /*Write to the page*/ form.txtResults.value = varResults + classWeekassign; } </script> </head> <body> <form id="myform" action="" method="get"> <table> <tr> <td colspan="2"><p> <select name="ddlSchool"> <option value="0">Prairie High School</option> <option value="1">Prairie Middle School</option> <option value="2">Prairie Elementary School</option> </select> <select name="ddlClass"> <option value="0">Reading</option> <option value="1">Math</option> <option value="2">Science</option> <option value="3">English</option> </select> <br /> </p></td> </tr> <tr> <td width="223"> <select name="ddlWeek"> <option value="0">Week 1</option> <option value="1">Week 2</option> <option value="2">Week 3</option> <option value="3">Week 4</option> </select></td> <td width="147"><input name="btnSubmit" type="button" value="Submit" onclick="test2(this.form)" /></td> </tr> <tr> <td colspan="2"><textarea name="txtResults" cols="50" rows="3"></textarea> </td> </tr> </table> </form> </body> </html> Similar TutorialsI am Having trouble getting this function to work. I am suppose to add javascript to a page to access an external js file named random.js to generate 5 random numbers when the page loads. it isnt doing it so far. Here is what i have. <html> <head> <script type="text/javascript" src="random.js"></script> <script type="text/javascript"> function showImg(o.jpg-9.jpg){ /* The showImg() function displays a random image from the 0.jpg through 9.jpg files. The random image is designed to thwart hackers attempting to endter the library database by requiring visual confirmation. */ var imgNumber= randomInteger(9);// Return a random number from 0 to 9. document.write("<img src='"+imgNumber+".jpg' alt='"+imgNumber+".jpg'/>"); } </script> </head> (<tr> <td colspan="2" class="center"> <script type= "text/javascript"> showlmg(); showlmg(); showlmg(); showlmg(); showlmg(); </script> </td> </tr> I have no clue where to start. I have to put a pop up box on the screen and have the user enter a number under 100 and tell them how many quarters dimes nickles and pennies that would be. PLEASE HELP I am stumped
I need desperate help with a homework! Here's the task: First of all I need to define an array of 3 elements. Each element is associated with a different first name. Then I shall realize a first function to add a name in the table. The function takes as parameter the table previously created and return it containing an additional element whose value is the name that the visitor wants to add. I must use the dialog box prompt so that the user can specify the name he wishes to add in the table. I shall also perform a second function which will display the name that is included in the different array elements. This function will also take the table in parameters and proceed with setting the display name with a dialog box alert type that contains all of the name separated by ";". Here's what I've done so far: HTML Code: Code: <html> <head> <title> Task #4 </title> </head> <body> <script language="javascript"> function addName() { var names=new Array(3); names[0]="John"; names[1]="Patrik"; names[2]="Jane"; document.open(); document.write(names[3].join()); document.close(); if(names==new Array); { prompt("What name do you want to add?"+""); } return addName } </script> <noscript> <h1> You're browser doesn't support Javascript </h1> </noscript> </body> </html> I don't really understand the second part of the task, but the first part is what I've written but it doesn't seem to do anything when I try it on my browser. What am I doing wrong? Thank you for your patience. -A Javascript newbie hi I need some help with a project I am working on. I spent time with my instructor but I lost something in translation. I know this is really basic but I really can't see what is wrong. we are trying to open employee payroll records and if the employee works 35hrs or less they get straight pay. anything over 35 is time and a half. I though my calculations were correct but if you calculate the first four records, which I wll post after the code, they are wrong. here is my code, Code: //constants var THIRTYFIVE = 35; var ONE_POINT_FIVE = 1.5; var ZERO = 0; //global variables var employeeNumber; var employeeName; var hourlyWage; var hoursWorked; var grossPay; var partOne; var partTwo; var totalForEmployee; var counter; var records; partOne = ZERO; partTwo = ZERO; totalForEmployee = 0; function calculateGrossPay() { while (records.readNextRecord()) { employeeNumber = records.getEmployeeNumber(); employeeName = records.getEmployeeName(); hourlyWage = records.getEmployeeHourlyWage(); hoursWorked = records.getEmployeeHoursWorked(); if (hoursWorked <= THIRTYFIVE) { partOne = hoursWorked * hourlyWage; } else { partOne = (hourlyWage * THIRTYFIVE); partTwo = ((hoursWorked - THIRTYFIVE) * hourlyWage) * ONE_POINT_FIVE; } totalForEmployee = partOne + partTwo; document.write(employeeNumber + "\t" + "\t" + employeeName + "\t" + totalForEmployee + "<br />"); } } /* this function prints the top row of the table */ function printHeader() { document.write("Employee" + "\t" + "Employee" + "\t" + "Gross" + "\t" + "\t" + "Withholding" + "\t" + "Net" + "\t" + "<br />" + "Number" + "\t" + "\t" + "Name" + "\t" + "\t" + "Pay" + "\t" + "\t" + "Amount" + "\t" + "\t" + "Pay" + "<br />" + "<br />"); } /* this function opens employee payroll records */ function initializeEmployeePayrollRecords() { records = openEmployeePayrollRecords(); } /* Design a program that will process the weekly employee time cards for all the employees of an organization. Each employee time card will have the these data items: an employee number, an employee name, an hourly wage rate, and the number hours worked during the week. Each employee is to be paid time-and-a-half for all hours worked over 35. A tax amount of 15% of gross salary is to be withheld. The output to the screen should display the employee's number and name, gross pay, withholding amount, and net pay. At the end of the report, display the total gross payroll amount, the total net payroll amount, and the average net pay paid per employee. */ function project4Part2() { // Your code goes in here. initializeEmployeePayrollRecords(); printHeader(); calculateGrossPay(); } this is the output I am getting Employee Employee Gross Withholding Net Number Name Pay Amount Pay 101 Joe Coyne 581.25 102 Fred Hensen 716.25 103 Ethel Roselle 1250 104 Barney Curry 1425 this is from the dataset, the first number is the wage, the second is the hours worked. 101 Joe Coyne 15 37.5 102 Fred Hensen 20 33 103 Ethel Roselle 25 45 104 Barney Curry 30 35 I would really appreciate any help with this, I am sure the answer is really simple but I am past the point of frustration. I need help with trying to figure out what exactly needs to be done with both of these homework assignments. Nothing we covered in the textbook or examples provided go along with these directions so I am at a lost. For one assignment we need to: Write a JavaScript script within a web page that will use prompt/alert dialog boxes to calculate an average value for a list of numbers that could be any size. Use a while loop that will prompt a user for a number. As long as the number is not zero or negative, continue to add the numbers up and count the total number of values entered. Once the user enters a zero or negative value, terminate the loop and calculate the average. Report this final value via an alert box. For the other assignment we need to: Write a JavaScript script that first asks the user to enter an integer value from 1..15. Validate this with an error checking that will not allow them to continue until they enter a proper number. After the input is validated, use this number to dynamically build an HTML table using a JavaScript loop with one row and including a number of columns matching the user input. Can someone please help me out on how I should go about coding for these two assignments, I am at a loss with these assignments. Hello all, I’ve got a homework to do and I'm stuck, as you can see i have done all the function's (i think they are ok but not shure) with a main program I'm stuck don’t know even where to begin :/ could anyone please please help a bit? best regards <HTML> <HEAD> <TITLE> The game of 21 </TITLE> <SCRIPT LANGUAGE = "JavaScript"> //FUNCTIONS /* *removes a given number of sticks * *function takes one argument numberToRemove that represents the number of sticks to be removed * if numberToRemove is more than numberOfSticks, reduces numberOfSticks to 0 * otherwise reduces numberOfSticks by numberToRemove *function returns no value */ function removeSticks(numberToRemove) { if (numberOfSticks< numberToRemove) { numberOfSticks =0 } else { (numberOfSticks = numberOfSticks - numberToRemove); } } /* *switches current player * *function takes no argument * if current player is 1, sets current player to 2 * otherwise sets current player to 1 *function returns no value */ function switchCurrentPlayer() { if (currentPlayer ==1) { return currentPlayer = 2; } { return currentPlayer = 1; } } /* *gets a number from a prompt dialogue * *function takes no argument * prompts the current player for a number of sticks to remove, with a suitable message *function returns the number the player enters */ function getChosenNumber() { ChosenNumber = window.prompt('Player ' + currentPlayer + ': Please enter either 1, 2 OR 3.'); return ChosenNumber; } //VARIABLES -- do not change this section var numberOfSticks = 21;//number of matchsticks, initially 21 var currentPlayer = 1;//player whose turn it is, Player 1 goes first var numberChosen;//variable used to hold the number the current player chooses //MAIN PROGRAM The players take turns to choose how many matches to remove, as long as there are still matches left. After each go the program outputs the number of matches that still remain and if this number is zero a message is displayed to say the current player is the winner. The turn then passes to the other player. </SCRIPT> </HEAD> <BODY> </BODY> </HTML> Hello, i have been trying to make a small one digit calculator, but i am having a lot of trouble with it..This is what i have so far. It will run each function individually, but if i try with all four sign functions, addition will only work....What am i doing wrong here? <!-- saved from url=(0014)about:internet --> <HTML> <HEAD> <TITLE>Page Title</TITLE> <SCRIPT language="JavaScript"> <!-- var n1 = -1; //1st operand of the expression -1 indicates n1 is empty var n2; //2st operand of the expression var startNew = true; var result; var operator; function readNumber(value) { if (n1 < 0) //n1 is empty { n1 = value; } else //n1 is not empty { n2 = value; } } function addition() { result = n1 + n2; //always deal with addition } function subtraction() { result = n1 - n2; //always deal with subtraction } function multiplication() { result = n1 * n2; //always deal with multiplication } function division() { result = n1 / n2; //always deal with division } function calculate_display() { //calculate the answer if (operator == '+') addition(); startNew = window.confirm(n1 + '+' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } if (operator == '-') subtraction(); startNew = window.confirm(n1 + '-' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } if (operator == '*') multiplication(); startNew = window.confirm(n1 + '*' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } if (operator == '-') division(); startNew = window.confirm(n1 + '/' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } } //--> </SCRIPT> </HEAD> <BODY> <form> <input type = "button" value="0" onclick="readNumber(0);"> <input type = "button" value="1" onclick="readNumber(1);"> <input type = "button" value="2" onclick="readNumber(2);"> <input type = "button" value="3" onclick="readNumber(3);"> <input type = "button" value="4" onclick="readNumber(4);"> <BR> <input type = "button" value="5" onclick="readNumber(5);"> <input type = "button" value="6" onclick="readNumber(6);"> <input type = "button" value="7" onclick="readNumber(7);"> <input type = "button" value="8" onclick="readNumber(8);"> <input type = "button" value="9" onclick="readNumber(9);"> <BR> <input type = "button" value="+" onclick="operator = '+';"> <input type = "button" value="-" onclick="operator = '-';"> <input type = "button" value="*" onclick="operator = '*';"> <input type = "button" value="/" onclick="operator = '/';"> <input type = "button" value="=" onclick="calculate_display();"> </form> Hello everybody, could anyone offer an insight into why this isn't work please? It should be a simple project I was given at college but it stops near the end. The task is to ask a user for a word using a form, then spell it out backwards — stupid, but, hey — it's a lesson! Here's the code: Thanks. <h2>JavaScript exercise 4</h2> <p>Ask the user for a string of text. This must then be displayed in reverse. (For example, if the user enters the words "Hello World!" an alert dialog box should appear with "!dlroW olleH") </p> <form action="javascript: displaymessage();" method="get"> <p>Please enter a word: <input id="user_word" name="user_wrd" type="text"> <input type="submit" value="Submit"> </p> </form> <script> function displaymessage() { /*Set a variable for the user's word*/ var word_forward; /*Get the user's word from the from above and put it into the variable*/ word_forward = document.getElementById("user_word").value; /*Write the user's word from the variable to the page*/ document.write("<p>The word is: " + word_forward + ".</p>"); /*Calculate the length of the user's word*/ var word_length=word_forward.length; /*Write the length of the user's word to the page*/ document.write("<p>The word length is: " + word_length + " characters.</p>"); /*Subtract 1 from word length to allow for character index numbers starting from zero*/ word_length2=(word_length-1); /*Set a variable for the character index number*/ var char_num; /*Begin character index number countdown loop: loop start value / loop end value / increment*/ for(char_num=word_length2; char_num=0; char_num--) { /*Write word backwards using charAt*/ document.write("The word spelled backwards is: " + word_forward.charAt(char_num)); } } </script> Hello coding forum users, I am working on the only javascript chapter of my HTML textbook. It asks me to: Quote: replace the line <img id="sky" src="sky0.jpg" alt=""/> with a script element that writes the following HTML code: <img id='sky' src='mapNum.jpg' alt=' ' /> where mapNum is the value of the mapNum variable. so I try PHP Code: <script type="text/javascript" /> document.write("<img id='sky' src='mapNum.jpg' alt=' ' />") </script> after a few other attempts I search codingforums and find: PHP Code: document.write("<img id=\"sky\" src='sky"+mapNum+".jpg' alt='' />"); and PHP Code: document.write('<img id="sky" src="sky'+mapNum+'.jpg" alt="" />'); and these work perfectly fine but I don't understand why? my textbook only has one javascript chapter and its really small and vague, and my teacher hasn't answered my emails, so I would be grateful if anyone can tell my why my first code falls flat. I am taking an online class and the instructor is no help whatsoever. Please see where I'm going wrong with this. I'm sure it is something small I'm missing. Thanks. The assignment is: Create a function named emLink() that writes an email address using text strings of the username and server names entered in reverse order as parameter values. The command to call the function would look as follows: emLink("eman","revres"). Call the stringReverse() function with name as the parameter value to reverse the order of characters. Code: <html> <head> <script type="text/javascript"> function emLink(name,server) { var rname="eman"; var rserver="revres"; stringReverse(rname); stringReverse(rserver); var email="eman@revres"; var mailText='<a href="mailto:eman@revres">"eman@revres"</a>'; document.write(mailText); } function stringReverse(textString) { if (!textString) return ''; var revString=''; for (i = textString.length-1; i>=0; i--) revString+=textString.charAt(i) return revString; } </script> </head> <body> <script type="text/javascript"> var rname="reldac"; var rserver="ude.ortsa.uwm"; emLink(rname,rserver); </script> </body> </html> Currently, all it returns it : "eman@revres" Hello, this is a homework project which kind of works but isn't perfect. My tutor said the result must be an alert but I ended up with a document.write instead. He said it was fine but I'd like to know how to make it alert the result if anyone can help. FWIW I tried making the contents of the for loop into a variable without success. Code: <form action="javascript: displaymessage();" method="get" /> <p>Please enter a word: <input id="user_word" name="user_wrd" type="text" /> <input type="submit" value="Submit" /> </p> <script type="text/javascript"> function displaymessage() { /*Set a variable for the user's word*/ var word_forward; /*Get the user's word from the form above and put it into the new variable*/ word_forward = document.getElementById("user_word").value; /*Write the user's word from the variable to the page*/ document.write('<p>The word is: ' + word_forward + '.</p>'); /*Calculate the length of the user's word*/ var word_length=word_forward.length; /*Write the length of the user's word to the page*/ document.write('<p>The word length is: ' + word_length + ' characters.</p>'); /*Subtract 1 from word length variable to allow for character index numbers starting from zero*/ word_length2=(word_length-1); /*Set a variable for the character index number*/ var char_num; /*Write the first part of the result line*/ document.write('The word spelled backwards is: '); /*Begin character index number countdown loop: loop start value / loop end value / increment*/ for(char_num=word_length2; char_num>=0; char_num--) { /*Write word backwards using charAt*/ document.write(word_forward.charAt(char_num) + " "); } } </script> Hey, I'm taking a javascript class and have to do an assignment in which I'm supposed to show countdowns to various events. I have 2 files, an external js file and a html file. But I can't get it to work I've searched the forum and googled it but all the solutions I've found do not work. Here's the code. .js file: Code: /* New Perspectives on JavaScript, 2nd Edition Tutorial 2 Review Assignment Author: Date: Function List: showDateTime(time) Returns the date in a text string formatted as: mm/dd/yyyy at hh:mm:ss am changeYear(today, holiday) Changes the year value of the holiday object to point to the next year if it has already occurred in the present year countdown(stop, start) Displays the time between the stop and start date objects in the text format: dd days, hh hrs, mm mins, ss secs */ function showDateTime(time) { var date = time.getDate(); var month = time.getMonth()+1; var year = time.getFullYear(); var second = time.getSeconds(); var minute = time.getMinutes(); var hour = time.getHours(); ampm = (hour < 12) ? " a.m." : " p.m."; hour = (hour > 12) ? hour - 12 : hour; hour = (hour == 0) ? 12 : hour; minute = minute < 10 ? "0"+minute : minute; second = second < 10 ? "0"+second : second; return month+"/"+date +"/"+year+" at "+hour+":"+minute+":"+second+ampm; } function changeYear (today, holiday) { var year = changeYear.getFullYear(); holiday.setFullYear(year); year = (today > holiday) ? year + 1 : year; year = holiday.setFullYear(year); } function countdown(start, stop) { time = stop - start; seconds = Math.floor(time/1000); minutes = Math.floor(seconds/60); hours = Math.floor(minutes/60); days = Math.floor(hours/24); return days + " days," + hours + " hours," + minutes + " mins," + seconds + " secs"; } And here's the HTML file: Code: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- New Perspectives on JavaScript, 2nd Edition Tutorial 2 Review Assignment Events in Tulsa Author: Date: Filename: events.htm Supporting files: dates.js, logo.jpg, tulsa.css --> <title>Upcoming Events at Tulsa</title> <link href="tulsa.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="dates.js"></script> <script type="text/javascript"> showCountdown(){ var today = new Date("October 31, 2010 10:00:00"); var Date1 = new Date("January 14, 2011 10:00:00"); var Date2 = new Date("May 21, 2011 12:00:00"); var Date3 = new Date("July 4, 2011 9:00:00"); var Date4 = new Date("September 1, 2011 12:00:00"); var Date5 = new Date("December 1, 2011 11:30:00"); var Date6 = new Date("December 31, 2011 3:30:00"); document.eventform.thisDay.value = showDateTime(today); changeYear(today, Date1); changeYear(today, Date2); changeYear(today, Date3); changeYear(today, Date4); changeYear(today, Date5); changeYear(today, Date6); document.eventform.count1.value = countdown(today, Date1); document.eventform.count2.value = countdown(today, Date2); document.eventform.count3.value = countdown(today, Date3); document.eventform.count4.value = countdown(today, Date4); document.eventform.count5.value = countdown(today, Date5); document.eventform.count6.value = countdown(today, Date6); } </script> </head> <body onload="setInterval('showCountdown()', 100)"> <form name="eventform" id="eventform" action=""> <div id="logo"> <img src="logo.jpg" alt="Tulsa Events" /> </div> <div id="links"> <a href="#">Home</a> <a href="#">City Services</a> <a href="#">City Agencies</a> <a href="#">Mayor's Office</a> <a href="#">News Today</a> <a href="#">Upcoming Events</a> <a href="#">Site Map</a> <a href="#">Search Engine</a> <a href="#">Public Notices</a> <a href="#">Survey Form</a> <a href="#">Contact Us</a> <a href="#">E-Government</a> </div> <div id="main"> <h3>Countdown to Upcoming Events</h3> <table> <tr> <th colspan="2" style="text-align: right">Current Date and Time</th> <td><input name="thisDay" id="thisDay" readonly="readonly" size="40" /></td> </tr> <tr> <th>Event</th> <th>Starting Time</th> <th>Countdown to Event</th> </tr> <tr> <td><input value="Heritage Day" readonly="readonly" size="20" /></td> <td><input value="Jan 14 at 10:00 a.m." readonly="readonly" size="20" /></td> <td><input name="count1" id="count1" size="40" /></td> </tr> <tr> <td><input value="Spring Day Rally" readonly="readonly" size="20" /></td> <td><input value="May 21 at 12:00 p.m." readonly="readonly" size="20" /></td> <td><input name="count2" id="count2" size="40" /></td> </tr> <tr> <td><input value="July 4th Fireworks" readonly="readonly" size="20" /></td> <td><input value="Jul 4 at 9:00 p.m." readonly="readonly" size="20" /></td> <td><input name="count3" id="count3" size="40" /></td> </tr> <tr> <td><input value="Summer Bash" readonly="readonly" size="20" /></td> <td><input value="Sep 1 at 12:00 p.m." readonly="readonly" size="20" /></td> <td><input name="count4" id="count4" size="40" /></td> </tr><tr> <td><input value="Holiday Party" readonly="readonly" size="20" /></td> <td><input value="Dec 1 at 11:30 a.m." readonly="readonly" size="20" /></td> <td><input name="count5" id="count5" size="40" /></td> </tr> <tr> <td><input value="New Year's Bash" readonly="readonly" size="20" /></td> <td><input value="Dec 31 at 3:30 p.m." readonly="readonly" size="20" /></td> <td><input name="count6" id="count6" size="40" /></td> </tr> </table> </div> </form> </body> </html> Thanks for your help, I appreciate it This post will contain a few guidelines for what you can do to get better help from us. Let's start with the obvious ones: - Use regular language. A spelling mistake or two isn't anything I'd complain about, but 1337-speak, all-lower-case-with-no-punctuation or huge amounts of run-in text in a single paragraph doesn't make it easier for us to help you. - Be verbose. We can't look in our crystal bowl and see the problem you have, so describe it in as much detail as possible. - Cut-and-paste the problem code. Don't retype it into the post, do a cut-and-paste of the actual production code. It's hard to debug code if we can't see it, and this way you make sure any spelling errors or such are caught and no new ones are introduced. - Post code within code tags, like this [code]your code here[/code]. This will display like so: Code: alert("This is some JavaScript code!") - Please, post the relevant code. If the code is large and complex, give us a link so we can see it in action, and just post snippets of it on the boards. - If the code is on an intranet or otherwise is not openly accessible, put it somewhere where we can access it. - Tell us any error messages from the JavaScript console in Firefox or Opera. (If you haven't tested it in those browsers, please do!) - If the code has both HTML/XML and JavaScript components, please show us both and not just part of it. - If the code has frames, iframes, objects, embeds, popups, XMLHttpRequest or similar components, tell us if you are trying it locally or from a server, and if the code is on the same or different servers. - We don't want to see the server side code in the form of PHP, PERL, ASP, JSP, ColdFusion or any other server side format. Show us the same code you send the browser. That is, show us the generated code, after the server has done it's thing. Generally, this is the code you see on a view-source in the browser, and specifically NOT the .php or .asp (or whatever) source code. I'm trying to get my Client Side Firefox DHTML app to display a list of eBooks. For this, i have the following files F:\Textbooks.html F:\eBooks.txt F:\FirstBook.txt F:\SecondBook.txt F:\ThirdBook.txt textbooks.html is my DHTML app eBooks.txt is the Library file with a listing of all of my eBooks. Inside of eBooks.txt is the following data: ----------------- FirstBook.txt, SecondBook.txt, ThirdBook.txt, ----------------- FirstBook.txt to ThirdBook.txt are my actual ebooks. The problem that i'm having is that When i try to click on any buttons other than the FirstBook button, i get the following error: ---------------------------------- Error: unterminated string literal Source File: file:///F:/Textbooks.html Line: 1, Column: 10 Source Code: LoadEbook(' ---------------------------------- So, unlike clicking on the FirstBook button, these other buttons do not load the eBook data into the DIV for displaying the eBook data. I use the DOM insepector to checkout the DOM of the button code, and it seems like whitespace maybe is the problem. However, i have removed whitespace from the HTMLdata string, and that's not fixing the problem. did i forget something silly? LOL i'm using FireFox 3.5 to develop this App. So obviously this will not work with anything other than Gecko Based browsers. here is my HTML code: <html> <head> <script language="JavaScript"> var eBookLibrary = "eBooks.txt"; var SystemPath = "f:" + String.fromCharCode(92) function Init() { // Initialize the eBook reader document.getElementById("EbookCanvas").style.visibility = "hidden"; document.getElementById("EbookToolbar").style.visibility = "visible"; document.getElementById("FileManager").style.visibility = "visible"; // Load the List of eBooks in the Library LoadBookList(); } function UpdateEbookList() { // Update the Library of Ebooks alert("Updating eBook Library"); // Go back to the File Manager, and Reload the List of Ebooks LoadBookList(); } function LoadBookList() { // This will load the list of books that are available var EbookList = LoadFromDisk(SystemPath + eBookLibrary); var EbookListArray = EbookList.split(","); for(var x = 0; x < EbookListArray.length -1; x++) { // Strip the Filename Extension off of the eBook File Name // The Name of the Book is always the first Index in the Array var BookName = EbookListArray[x].split("."); // Remove the weird whitespace - it screws things up...i think... BookName[0] = BookName[0].replace(/(^\s*|\s*$)/g, ""); var HTMLdata = HTMLdata + "<input type='button' value='" + "FirstBook" + "'" + " onClick=LoadEbook('" + EbookListArray[x] + "');><br>"; } // For some ****ed up reason the first string always generates an 'undefined' even though it's nonsense // So just delete that from the HTMLdata string, because it's just ugly - LOL HTMLdata = HTMLdata.replace("undefined", ""); HTMLdata = HTMLdata.replace("", " "); // Write the HTML data to the DIV document.getElementById("FileManager").innerHTML = HTMLdata; } function LoadEbook(EbookName) { // Hide the File Manager and Show the Ebook Canvas document.getElementById("FileManager").style.visibility = "hidden"; document.getElementById("EbookCanvas").style.visibility = "visible"; document.getElementById("EbookToolbar").style.visibility = "visible"; // Load the Ebook content into the Ebook Reader Pannel var EbookContent = LoadFromDisk(SystemPath + EbookName); document.getElementById("EbookCanvas").innerHTML = EbookContent; } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } </script> </head> <body onLoad="Init();"> <div id="FileManager" style="position: absolute; top: 0px; left: 0px; visibility: visible;"> The eBook Library's List of Books will be listed here. Click on one to open it in the eBook Reader </div> <br> <div id="EbookCanvas" style="position: absolute; top: 0px; left: 0px; visibility: hidden;"> </div> <br> <div id="EbookToolbar" style="position: absolute; top: 100px; left: 0px;"> <input type="button" value="Open" OnClick="Init();"> <input type="button" value="Update" OnClick="UpdateEbookList();"> <input type="button" value="Exit" OnClick="MainMenu();"> </div> </body> </html> Hi all, I hope someone can advise whether such a script exists for what am wanting to do. From time to time, I need to send password information or login details and password information to some users. At the moment, am doing it via email with a subject named FYI and the body of the email basically just contain the login and the password or in some case, just the password. What am wanting to know is whether I can put these information into a HTML file which contains an obfuscated Javascript with a button that a user will click that will prompt for his login information and then will display the password. In its simplest form, I guess I am looking for a Javascript that will obfuscate a HTML file that contains the password. Anyway, hopefully someone understand what am looking for. I found some website that offers such service as obfuscating a HTML file but am hoping it can be done via a Javascript so it is at least "portable" and I do not have to be online. Any advice will be much appreciated. Thanks in advance. I am trying to set up a looping structure that tests to see if the user enters a value. If the textbox is null then a global variable is false otherwise a checkbox is checked and the global variable is true. below is what i have done so far, please assist me. var isValid = false; window.onload = startForm; function startForm() { document.forms[0].firstName.focus(); document.forms[0].onsubmit = checkEntries; alert("You have been added to the list") } function checkEntries() { var menus = new Array(); var formObject = document.getElementsByTagName('*'); for (var i=0; i < formObject.length; i++){ if (formObject[i] == "myform") menus.push(formObject[i]); if (document.forms[0].firstName.value.length==0 || document.forms[0].firstName.value.length == null){ isValid= false; alert("Please enter a first name"); } else (document.forms[0].check0.checked=true); isValid=true; if (document.forms[0].lastName=="" || document.forms[0].lastName== null){ alert("Please enter a last name"); isValid = false; } else (document.forms[0].check1.checked=true); isValid=true; if (document.forms[0].email=="" || document.forms[0].email== null) { alert("Please enter a valid email"); } else return (document.forms[0].check0.checked=true); isValid=true; if (document.forms[0].bDate=="" || document.forms[0].bDate== null) { isValid=false; alert("please make sure you enter a valid birth date."); } else (document.forms[0].check0.checked=true); isValid=true; } } here is the form html... <form name="myform" > <input type="checkbox" name="check0" class="check0" id="check0" > First: <input type="text" name="firstName" id="firstName"> <BR> <input type="checkbox" name="check1" class="check1" id="check1" > Last: <input type="text" name="lastName" id="lastName" ><BR> <input type="checkbox" name="check2" class="check2" id="check2" > E-Mail: <input type="text" name="email" id="email"> <BR> <input type="checkbox" name="check3" class="check3" id="check3" > Birthday (mm/dd/yyyy): <input type="text" name="bDate" id="bDate"> <BR> <input type="submit" value="Join our mailing List" /> </form> Hey everyone here is my code for looking up a city, and state by zip code. I am getting no errors and i believe it should work, but the code does not seem to want to function. Any ideas? Here is my 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=utf-8" /> <title>City and State Lookup</title> <style type="text/css"> h1 { font-family:Arial; color:navy; } p, td { font-family:arial; font-size:11px; } </style> <script type="text/javascript"> /* <![CDATA[ */ var httpRequest = false; function getRequestObject() { try { httpRequest = new XMLHttpRequest(); } catch (requestError) { try { httpRequest = new ActiveXObject ("Msxm12.XMLHTTP"); } catch (requestError) { try { httpRequest = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (requestError) { window.alert("Your browser does not support AJAX!"); return false; } } } return httpRequest; } function updateCityState() { if (!httpRequest) httpRequest = getRequestObject(); httpRequest.abort(); httpRequest.open("get","zip.xml"); httpRequest.send(null); httpRequest.onreadystatechange=getZipInfo; } function getZipInfo() { if (httpRequest.readyState==4 && httpRequest.status == 200) { var zips = httpRequest.responseXML; var locations = zips.getElementsByTagName("Row"); var notFound = true; for (var i=0; i<locations.length; ++i) { if (document.forms[0].zip.value == zips.getElementsByTagName( "ZIP_Code")[i].childNodes[o].nodeValue) { document.forms[0].city.value = zips.getElementsByTagname( "City") [i].childNodes[0].nodeValue; document.forms[0].state.value = zips.getElementByTagName( "State_Abbreviation")[i].childNodes[0].nodeValue; notFound = flase; break; } } if (notFound) { window.alert("Invalid ZIP code!"); document.forms[0].city.value = ""; document.forms[0].state.value = ""; } } } /* ]]> */ </script> </head> <body> <h1>City and State Lookup </h1> <form action=""> <p>Zip code <input type="text" size="5" name="zip" id="zip" onblur="updateCityState()" /></p> <p>City <input type="text" name="city" /> State <input type="text" size="2" name="state" /></p> </form> </body> </html> Hi guys.. I really need a bit of help.. is anyone looking at this good with JS? I have a php form validation script but i think its a bit slow and would rather a JS script instead... here is what i have in php.. PHP Code: <?php if(isset($_POST['submit'])) { $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $mobile = $_POST['mobile']; $comments = $_POST['comments']; $errors = array(); function display_errors($error) { echo "<p class=\"formMessage\">"; echo $error[0]; echo "</p>"; } function validateNames($names) { return(strlen($names) < 3); } function validateEmail($strValue) { $strPattern = '/([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})/sim'; return(preg_match($strPattern,$strValue)); } function validateMobile($strValue) { $strPattern = '/^\d{10}$/'; return(preg_match($strPattern,$strValue)); } function validateComments($comments) { return(strlen($comments) < 10); } if(validateNames($firstName)) { $errors[] = 'Please Enter Your First Name'; } if(validateNames($lastName)) { $errors[] = 'Please Enter Your Second Name'; } if(!validateEmail($email)) { $errors[] = 'Please Enter Your Correct Email'; } if(!validateMobile($mobile)) { $errors[] = 'Please Enter Your Correct Mobile Number'; } if(validateComments($comments)) { $errors[] = 'Please Enter A Comment More Than 10 Characters'; } if(empty($errors)) { $to = "info@eventpromotion.ie"; $subject = "Event Promotion Enquiry!"; $body = "First Name: " . $_POST['firstName'] . "\nLast Name: " . $_POST['lastName'] . "\nEmail: " . $_POST['email'] . "\nMobile: " . $_POST['mobile'] . "\nMessage: " . $_POST['comments']; $headers = "From: ". $firstName ." ". $lastName . " <" . $email . ">\r\n"; if (mail($to, $subject, $body, $headers)) { echo("<p class=\"formMessage\">Thanks for submitting your enquiry.</p>"); } else { echo("<p class=\"formMessage\">Message delivery failed.</p>"); } } else { //echo "error"; display_errors($errors); } } ?> <form id="form" method="post" action="index.php#quickContact"> <p> <label>First Name</label><br /> <input type="text" name="firstName" value="<?php if(isset($firstName)){echo $firstName;} ?>" /> </p> <p> <label>Last Name</label><br /> <input type="text" name="lastName" value="<?php if(isset($lastName)){echo $lastName;} ?>" /> </p> <p> <label>Email:</label><br /> <input type="text" name="email" value="<?php if(isset($email)){echo $email;} ?>" /> </p> <p> <label>Mobile:</label><br /> <input type="text" name="mobile" value="<?php if(isset($mobile)){echo $mobile;} ?>" /> </p> <p> <label>Comments:</label> <br /> <textarea name="comments" cols="30" rows="3" ><?php if(isset($comments)){echo $comments;} ?></textarea> </p> <p> <input class="send" type="image" src="images/submit2.gif" name="submit" value="Submit" /></p> </form> does anyone know how to transfer this to JS so that it will be easy to understand.. Im not good with JS at all |