JavaScript - Help With Code Please, I Cant Get My If Statement To Work...
So when I enter in numbers for the calculator the numerical grade shows, but not the letter grade. I dont know if I called the function wrong or if my if statement is wrong. I have no idea. Can someone help me please?
Code: <!DOCTYPE html> <html lang="en"> <head> <title>Lab</title> <meta charset="utf-8"> <script> function calculateGrade () { var test1 = document.getElementById("t1") var test2 = document.getElementById("t2") var finalexam = document.getElementById("t3") var labs = document.getElementById("t4") var projects = document.getElementById("t5") var quizzes = document.getElementById("t6") var grade= document.getElementById("fng") grade.value=parseFloat(0.15*test1.value)+parseFloat(0.15*test2.value)+parseFloat(0.20*finalexam.value)+parseFloat(0.30*labs.value)+ parseFloat(0.05*projects.value)+parseFloat(0.15*quizzes.value) } function getLetterGrade() { if (totalGrade >= 90) letterGrade = "A"; else if (totalGrade < 90 && totalGrade >= 80) letterGrade = "B"; else if (totalGrade < 80 && totalGrade >= 70) letterGrade = "C"; else if (totalGrade < 70 && totalGrade >= 60) letterGrade = "D"; else if (totalGrade < 60 && totalGrade >= 50) letterGrade = "F"; } </script> </head> <body> <form id="form1" name="form1"> <table> <tr> <th colspan="2"> Score </th> </tr> <tr> <td> Test 1 </td> <td><input type="text" name="t1" id="t1" value= ""></td> </tr> <tr> <td> Test 2 </td> <td><input type="text" name="t2" id="t2" value= ""></td> </tr> <tr> <td> Final Exam </td> <td><input type="text" name="t3" id="t3" value=""></td> </tr> <tr> <td> Labs </td> <td><input type="text" name="t4" id="t4" value=""></td> </tr> <tr> <td> Projects </td> <td><input type="text" name="t5" id="t5" value=""></td> </tr> <tr> <td> Quizzes </td> <td><input type="text" name="t6" id="t6" value=""></td> </tr> <tr> <th colspan="2"> <input type="button" name="b1" id="b1" value="Calculate Grade" onclick="calculateGrade(); getLetterGrade()"> </th> </tr> <tr> <td> Final numerical grade </td> <td><input type="text" name="fng" id="fng" style="border: none"></td> </tr> <tr> <td> Final letter grade </td> <td><input type="text" name="letterGrade" id="letterGrade" style="border: none"></td> </tr> </table> </form> </body> </html> Similar TutorialsI have a page with a Geo IP redirect that's supposed to redirect users from London to URL#1 and the rest to URL#2. It's an external geo ip lookup service. First comes the IP lookup: Code: <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"> /* GeoIP Deny Access by City and Redirect Javascript 1.0 http://wiki.category5.tv/MaxMind_GeoIP_API API (c) MaxMind - www.maxmind.com - used with permission "GeoIP Deny Access by City" script by Robbie Ferguson, www.Category5.TV You are free to use and share this script, however this notice must remain intact. */ </script> And then, and here's the problem I think, is the redirects inside an if/else: Code: <script type="text/javascript"> var city=new Array("London, H9") var redirect="http://www.URL1.com" var redirect2="http://www.URL2.com" /* do not edit past this line */ Array.prototype.inArray = function(q) { for(i in this) { if(this[i].toUpperCase() === q) return true; } } var myCity=geoip_city().toUpperCase() var myRegion=geoip_region().toUpperCase() if(city.inArray(myCity+", "+myRegion)) { window.location = redirect; } else { window.location = redirect2; } The redirect works if you are indeed from London. So if the if-statement is true, "window.location = redirect" works, but if the statement is not true, "window.location = redirect2" doesn't seem to be called. Help would be extremely appreciated Ive searched on this board but cant find out why this doesn't work. Code: <script type="text/javascript"> function showSelected(val) if (val == "Nil") { document.getElementById('JustText').innerHTML='hi' } else { document.getElementById('selectedResult').innerHTML="<a href='mailto:" + val + "'>" + val + "</a><p>" } </script> Hey everyone, I'm a newbie writing a tic tac toe program using OOP. It was simple setting it up so that a player could click on a box to put an X or an O there, but I've run into serious issues when trying to make it so a player couldn't overwrite the AI's choice and the AI couldn't overwrite the player's. An example of this would be if I made the top right box an X and the AI then made the center box an O, and then I accidentally clicked the center box and made it into an X. I want to prevent that. Every box on the grid is an object with the property of "taken" that helps the program know if a box is empty or not, so as to avert any overwriting in the first place. If the box is empty, this.taken = 0. If the box is filled by a player, taken = 1. If filled by AI, taken = 2. I made it matter whether it was AI or human so later i can check if one of them got tic tac toe. Anyway, by default the constructor class sets this.taken = 0. But the method for checking availability and writing the X or O uses a switch which checks if taken = 0. If it is, it sets taken to either 1 or 2 and writes the necessary symbol. If taken = 1 or 2, it just alerts the player that the spot is taken. But for some reason the switch statement can't tell when taken = anything other than 0. It always executes the code for 0 even though the code for 0 inherently makes it so that taken never equals 0 again, which means case 0 cannot happen anymore. Below is the code with notes. Code: function main(input){//start of main function// function Click(who, where, what){ //this is the method for checking if it's taken or not and writing the X or O if it isn't// /*the argument who represents a number. 0 is no one, 1 is human, 2 is AI; where is a string literal representing the spot on the grid*/ switch(this.taken){ case 0: this.taken = who; document.getElementById(where).innerHTML = what; break; case 1: alert("this spot is taken"); break; case 2: alert("this spot is taken"); }//end switch }//end Click function Box(inputhere){//start of class// this.taken = 0; this.pick = Click; } //end of Box class// //object declarations (I cut out most of them and left only the relevant ones// var topleft = new Box(); var topmid = new Box(); var topright = new Box(); var centerright = new Box(); //end of object declarations// switch (input){ /*in each .pick(), the first arg is whether or not a player chose it (1 = player did, 2 = comp did). The second arg is which box and the third is whether to put an X or O. The input variable in the switch statement is an argument passed through main() when the player clicks on a box. Topleft passes 1.1, topmid passes 1.2 and so on.*/ case 1.1:{ //The first instance of .pick() in each case is what the player did. The second is what the AI will do in repsonse.// topleft.pick(1, "topleft", "X"); topmid.pick(2, "topmid", "<span>O</span>"); break; }//end of case 1.1 case 1.3:{ topright.pick(1, "topright", "X"); centerright.pick(2, "centerright", "<span>O</span>"); break; }//end of case 1.3 }//end of switch }//end of main// Is there anyone who has any idea why on earth this is happening? I've been at it for an embarrassing amount of hours. Also, thanks to anyone who even considers helping : ) (feel free to flame me if my code sucks or my post is too long or anything). Hi, I am new here without any coding skills but willing to learn. I know how to use html code. I am thinking of how to write the code for below scenario to create a simple online customize calculator: There is 1 box which allow us to enter any number=x (representing amount of money). So whenever we entered a number in the box and click "CALCULATE" buton below the box, there will be 3 results generated in 3 boxes below it based on the set of of rules i.e. 1. if the amount entered is <21,000 Result 1 = 1.5%*x*12 Result 2 = 1.5%*x*48 Result 3 = 1.5%*x*120 2. if the amount entered is >=21,000 and <210,000 Result 1 = 1.8%*x*12 Result 2 = 1.8%*x*48 Result 3 = 1.8%*x*120 3. if the amount entered is >=210,000 Result 1 = 2.2%*x*12 Result 2 = 2.2%*x*48 Result 3 = 2.2%*x*120 I understand that this code will involve If...else if...else Statement.. Anyone can give me any references/examples similar to this scenario? Thanks. Hi everyone, I'm a beginner who has now come across the switch statement and has been trying to understand it with this simple coding i came up with. I think I have the syntex of the switch command correct but I'm trying to get it to work along with a HTML form and a function. I've been trying to figure out what i am do wrng but can not seem to see the solution. can someone guide me to the solution? thanks John Code: <html> <head> <title>Using the switch statement.</title> <script type="text/javascript"> function basegraincheck(){ var basegrain = document.basegrainform.basegrain1.value return basegrain } switch (basegrain) { case 1 : displaygrain = "US Pale ale malt" break case 2 : displaygrain = "Maris Otter Malt" break case 3 : displaygrain = "Crystal Malt" break default: displaygrain = "somethings wrong with the switch statement" } document.write(displaygrain); </script> </head> <body> <form name="basegrainform" action="" method="get" onsubmit="basegraincheck()"> <h2>Select a grain</h2> <br> <p>Pale ale Malt</p> <input type="radio" name="basegrain1" value="1"> <br> <p>Maris Otter Malt</p> <input type="radio" name="basegrain1" value="2"> <br> <p>Crystal Malt</p> <input type="radio" name="basegrain1" value="3"> <br> <input type="submit" value="Submit"> </form> </body> </html> function paymentmeth() { for (i = 0; i < document.merch.payway.length; i++){ if (document.merch.payway[i].checked == true){ //a loop that is used to determine the paymethod and checks to see if data has been entered method = document.merch.payway[i].value } } if (method == false) { alert("You forgot to select Pay Method.") } } Hi, i got good help with this last time but i still wonder if its possible to make this work in ie explorer. The script is a expandable menu where the submenus still shall be shown if javascript is disabled for some reason, it works in firefox but i in ie it shows all links as submenus on load . i wonder if it would be possible to show the menus unexpanded on load in i explorer to . note that the submenus should only be visible on load if javascript is disabled. Im posting the code below i would aprreciate some help <!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>Untitled Document</title> <style type="text/css"> .menu1{ margin-left:25px; padding-left:20px; padding-top:2px; padding-bottom: 2px; display:block; text-decoration: none; color: #000000; height: 20px; width: 200px; background-color: #03C; border: thin solid #FFF; } .submenu{ background-image: url(images/submenu.gif); display: block; height: 19px; margin-left: 38px; padding-top: 2px; padding-left: 7px; color: #333333; } .hide{ display: none; } .show{ display: block; } </style> </head> <body> <a class="menu1" onclick="showHide('mymenu1')">Menu 1</a> <div id="mymenu1" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu2')">Menu 2 </a> <div id="mymenu2" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu3')">Menu 3 </a> <div id="mymenu3" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu4')">Menu 4 </a> <div id="mymenu4" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu5')">Menu 5 </a> <div id="mymenu5" class="show"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <script type="text/javascript"> menu_status = new Array(); function showHide(theid){ var switch_id = document.getElementById(theid); if(menu_status[theid] != 'show') { switch_id.className = 'show'; menu_status[theid] = 'show'; } else { switch_id.className = 'hide'; menu_status[theid] = 'hide'; } } var divs=document.getElementsByTagName('div'); var menudivs=[]; for(i=0;i<divs.length;i++) { if(divs[i].id.indexOf('mymenu')!=-1) menudivs.push(divs[i]); } function hideDivs() { for(i=0;i<menudivs.length;i++) { menudivs[i].className='hide'; menu_status[menudivs[i]]='hide'; } } window.addEventListener('load',hideDivs,false); //window.attachEvent('onload',hideDivs) - add this within an "if IE" statement </script> </body> </html> Hi everyone, Kind of new to this but I can't get my page to work in IE, works fine in all other browsers though. Any help would be greatly appreciated! the site is sthfilm.com and the code is below: Code: <html> <head> <title>Shortcut to Heaven</title> <link rel="stylesheet" href="style.css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" charset="utf-8"> </script> <script type="text/javascript"> <!-- Activate cloaking device var randnum = Math.random(); var inum = 4; var rand1 = Math.round(randnum * (inum-1)) + 1; images = new Array images[1] = "img/bg.jpg" images[2] = "img/bg2.jpg" images[3] = "img/bg3.jpg" images[4] = "img/bg4.jpg" var image = images[rand1] // Deactivate cloaking device --> $(function(){ var menu = $('#menu'), pos = menu.offset(); $(window).scroll(function(){ if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){ menu.fadeOut('fast', function(){ $(this).removeClass('default').addClass('fixed').fadeIn('fast'); }); } else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){ menu.fadeOut('fast', function(){ $(this).removeClass('fixed').addClass('default').fadeIn('fast'); }); } }); }); $(function(){ var bar = $('#bar'), pos = bar.offset(); $(window).scroll(function(){ if($(this).scrollTop() > pos.top+bar.height() && bar.hasClass('default2')){ bar.fadeOut('fast', function(){ $(this).removeClass('default2').addClass('fixed2').fadeIn('fast'); }); } else if($(this).scrollTop() <= pos.top && bar.hasClass('fixed2')){ bar.fadeOut('fast', function(){ $(this).removeClass('fixed2').addClass('default2').fadeIn('fast'); }); } }); }); </script> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <script language="JavaScript"> <!-- Activate cloaking device document.write('<img src="' + image + '" class="bg">') // Deactivate cloaking device --> </script> <div id="navi"> <div id="bar" class="default2" align=center> <div id="menu" class="default" align=center> <!--code of floating bar goes here--> <h1>For additonal information on this project please contact ...</a></h1> </div> </div> </div> </body> </html> For some reason it does not work. It should when a player value is = NaN than the players NaN value should be equal to the players value before he was NaN Code: <script type="text/javascript"> function start(){ var t=setTimeout("roll()",500); var t=setTimeout("p11()",1000); var t=setTimeout("roll()",3001); var t=setTimeout("p12()",4002); var t=setTimeout("roll()",5003); var t=setTimeout("p13()",6004); var t=setTimeout("roll()",7005); var t=setTimeout("p14()",8006); var t=setTimeout("roll()",9006); var t=setTimeout("start()",9007); } function roll(){ var a = randoma=Math.floor(Math.random()*7); var b = randomb=Math.floor(Math.random()*7); document.getElementById("r1").value = a; document.getElementById("r2").value = b; } </script> <script type="text/javascript"> function p11(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n1").value == document.getElementById("p1").value ; document.getElementById("p1").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } } </script> <script type="text/javascript"> function p12(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n2").value == document.getElementById("p2").value ; document.getElementById("p2").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; } } </script> <script type="text/javascript"> function p13(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n3").value == document.getElementById("p3").value ; document.getElementById("p3").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; } } </script> <script type="text/javascript"> function p14(){ if (document.getElementById("r1").value == document.getElementById("r2").value ) { document.getElementById("n4").value == document.getElementById("p4").value ; document.getElementById("p4").value = "NaN"; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p2").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p3").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; document.getElementById("p1").value ++; } if (document.getElementById("r1").value < document.getElementById("r2").value ) { document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } if (document.getElementById("r1").value > document.getElementById("r2").value ) { document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; document.getElementById("p4").value ++; } } </script> Code: Player 1 $<input type="text" value="0" id="p1" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 2 $<input type="text" value="0" id="p2" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 3 $<input type="text" value="0" id="p3" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 4 $<input type="text" value="0" id="p4" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> <input type="button" value="Roll" onclick="start()"/> <br/> <input type="hidden" value="0" id="r1" size="1" /> <input type="hidden" value="0" id="r2" size="1" /> Player 1 NaN $<input type="text" value="0" id="n1" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 2 NaN $<input type="text" value="0" id="n2" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 3 NaN $<input type="text" value="0" id="n3" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> <br/> Player 4 NaN $<input type="text" value="0" id="n4" size="1" style="background-color:transparent;border:0px solid white;"Readonly /> OK I am stumped. I am creating a little html to check my js file. I want to have the user enter two parameters and then call the function using those two paramaters and then display the answer on the screen. Here is the html file <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>HomeWork3</title> <script type="text/JavaScript" src="grosspay.js"> </script> </head> <body> <script type="text/javascript"> <![CDATA[ var hoursWorked = parseInt(prompt("Enter the Number of Hours You Worked", "40")); var hourlyRate = parseInt(prompt("Enter the Number of Hours You Worked", "10")); function grossPay(hoursWorked, hourlyRate){ document.writeln(grossPay + " Is your normal amount of your check before taxes are taken out"); } ]]> </script> </body> </html> Here is the JS file function grossPay (hoursWorked, hourlyRate) { if (hoursWorked > 40){ var overTimeHrs = (hoursWorked - 40) var overTimePay = (overTimeHrs * 1.5 * hourlyRate) var regPay = (40 * hourlyRate) var grossPay = regPay + overTimePay return grossPay }else { var grossPay = (40 * hourlyRate) return grossPay} } CAN SOMEONE PLEASE HELP I have this javascript code in this html page and it works fine. As soon as I try to add it to an existing page, it doesn't work. I have tried every position for the form and the script that I can think of but to no avail. I would greatly appreciate soon expert guidance. Frank. The code page is here. The page that I am trying to add it to is here. Hi, I have a javascript I created to compare the textbox value to the array and write something on the textbox but somehow it is giving me a syntax error. I am not good in javascript so I am really not sure which one is giving me problem. Can someone please help? Thanks. My logic is to check if my 18 textbox is not empty and if not then get the label of each textbox and compare to my array listed below. If the value of each label in the textbox exist, then write and equal word in the hidden textbox and if it doesn't exist, increment to the value of 1 to the textbox. Here is my javascript code: Code: function CalculateTotal(){ var homelessness = new Array (); homelessness[0] = "70250", homelessness[1] = "70260", homelessness[2] = "70750", ); var financial = new Array (); financial[0] = "96580", financial[1] = "96500", financial[2] = "96580", ); var emergency = new Array (); emergency[0] = "79660", emergency[1] = "80105", emergency[2] = "96020", ); for (i=3; i<18; i++) for (var k=3; k<18; k++) { if((amounts[i] != "") && (amounts[i] == desig[k])) { var issueId = impact.charAt(k); var impact_txt = document.getElementById(issueId).value; for ( var x = 0; x < homelessness.length; x++ ) { var myArray[ homelessness[ x ] ] = homelessness[ x ]; if ( myArray[impact_txt] == homelessness[] ) && (document.getElementById('impact1').value == "")) { document.getElementById('impact1').value = "Homelessness"; } } for ( var x = 0; x < financial.length; x++ ) { var myArray[ financial[ x ] ] = financial[ x ]; if ( myArray[impact_txt] == financial[] ) && (document.getElementById('impact2').value == "")) { document.getElementById('impact2').value = "Financial Stability and Independence"; } } for ( var x = 0; x < emergency.length; x++ ) { var myArray[ emergency[ x ] ] = emergency[ x ]; if ( myArray[impact_txt] == emergency[] ) && (document.getElementById('impact2').value == "")) { document.getElementById('impact3').value = "Emergency Crisis and Services"; } } } } } } //body code <table> <tr> <td style="width:380px;text-align:left"><label for="d" id="D" name="D" title="80104">Crime and Drug Use <a href="javascript:alert('');">what is this?</a></label></td> <td style="float:right"> $<input id="d" name="d" class="text" type="text" value="<?php safeEcho($form['d'])?>" style="width:90px;" onChange="CalculateTotal();" /> <?php helper_error('d');?> </td><td> <input name="impact1" id="impact1" type="text" value="" onclick="CalculateTotal();" /> </td> </tr> <tr> <td style="width:380px;text-align:left"><label for="e" id="E" name="E" title="80101">Early Childhood Development <a href="javascript:alert('');">what is this?</a></label></td> <td style="float:right"> $<input id="e" name="e" class="text" type="text" value="<?php safeEcho($form['e'])?>" style="width:90px;" onChange="CalculateTotal()" /> <?php helper_error('e');?> </td><td> <input name="impact2" id="impact2" type="text" value="" onclick="CalculateTotal();" /> </td> </tr> <tr> <td style="width:380px;text-align:left"><label for="f" id="F" name="F" title="80105">Emergency and Crisis Services <a href="javascript:alert('');">what is this?</a></label></td> <td style="float:right"> $<input id="f" name="f" class="text" type="text" value="<?php safeEcho($form['f'])?>" style="width:90px;" onChange="CalculateTotal()" /> <?php helper_error('f');?> </td><td> <input name="impact3" id="impact3" type="text" value="" onclick="CalculateTotal();" /> </td> </tr> Hope you can help me to make my javascript work. Thanks. Code: function dimensions(){ $('.resource-container').css("width",($(window).width() - 306) + 'px'); $('.resource-title').css("width",($(window).width() - 366) + 'px'); $('.resource-container').css("height",($(window).height() - 250) + 'px'); $('.resource-content ul').css("height",($(window).height() - 292) + 'px'); $('.resource-iframe').css("width",($(window).width() - 306) + 'px'); $('.resource-iframe').css("height",($(window).height() - 275) + 'px'); } function resourcego(id){ $.ajax({ url: "http://glynit.co.cc/resource.php?id=" + id + "&item=list&part=name", cache: false, success: function(data){ name = data; $.ajax({ url: "http://glynit.co.cc/resource.php?id=" + id + "&item=list&part=list", cache: false, success: function(data){ list = data; $('.resource-toolbar').html('<div id="resource-title" class="resource-title">' + name + '</div>'); $('.resource-content').html('<div class="resource-list"><ul>' + list + '</ul></div>'); dimensions(); } }); } }); } function viewresource(id,ref){ $.ajax({ url: "http://glynit.co.cc/resource.php?id=" + id + "&content=name", cache: false, success: function(data){ name = data; $('.resource-toolbar').html('<div id="resource-back" class="resource-back" onclick="resourcego(' + ref + ');">Back</div><div id="resource-title" class="resource-title">' + name + '</div><div id="resource-print" class="resource-print">Print</div>'); $('.resource-content').html('<iframe id="resource-iframe" class="resource-iframe" src="http://glynit.co.cc/resource.php?id=' + id + '&content=content"></iframe>'); dimensions(); } }); } $(window).load(function() {dimensions();}); $(window).resize(function() {dimensions();}); The webiste is http://www.glynit.co.cc/ and the login is guest:guest And the page is the resources page and it is the links on the left of that page that do not work. Hi,my current pop under code works ever 24hrs,but I would like to change it to work every hour,and/or to work every time a member clears his cookies.If I am not explaining this correctly please let me know and I will try to correct this. Code: function setCookie(name, value, time) { var expires = new Date(); expires.setTime( expires.getTime() + time ); document.cookie = name + '=' + value + '; expires=' + expires.toGMTString(); } Any help with this would be greatly appreciated!! Mike Edit:If you need me to post the whole code I have no prob with this.I only posted this part because I thought the issue would be in var expires = new Date();. Just want to know what should I change it to? Here is the whole code. Code: <script type="text/javascript"> var puShown = false; function doOpen(url) { if ( puShown == true ) { return true; } win = window.open(url, 'wmPu', 'toolbar,status,resizable,scrollbars,menubar,location,height=700,width=1100'); if ( win ) { win.blur(); puShown = true; } return win; } function setCookie(name, value, time) { var expires = new Date(); expires.setTime( expires.getTime() + time ); document.cookie = name + '=' + value + '; expires=' + expires.toGMTString(); } function getCookie(name) { var cookies = document.cookie.toString().split('; '); var cookie, c_name, c_value; for (var n=0; n<cookies.length; n++) { cookie = cookies[n].split('='); c_name = cookie[0]; c_value = cookie[1]; if ( c_name == name ) { return c_value; } } return null; } function initPu() { if ( document.attachEvent ) { document.attachEvent( 'onclick', checkTarget ); } else if ( document.addEventListener ) { document.addEventListener( 'click', checkTarget, false ); } } function checkTarget(e) { if ( !getCookie('popundr') ) { var e = e || window.event; var win = doOpen('My Site Name Here/'); setCookie('popundr', 1, 24*60*60*1000); } } initPu(); </script> I do know that most of you hate pop ups and pop unders,but this is not to annoy my users.I am just using this to promote another site that I own..Thanks again. Code: var f = []; for ( var f1 = 1; f1 <= n; ++f1 ) { var f2 = n / f1; if ( f2 == Math.floor(f2) ) { f.push(f1); f.push(f2); } if ( f2 <= f1 ) break; } f.sort(); Someone helped me make this factoring code, but if n = 6, it returns [1,2,2,3,3,6,6,6] Any ideas? I am looking for [1,2,3,6] Hello, I have a script that lets you add tasks to a task list and then you can click a button to sort them, but I cannot get the "Delete Selected Task" and "Delete All Tasks" buttons to work correctly. I will be eternally indebted to whoever can help me fix these two buttons. The code I am working on is posted below. Thank you for your 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" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>To Do List</title> <script type="text/javascript"> /* <![CDATA[ */ function addTask() { if (document.forms[0].newtask.value == "") window.alert("You must enter a value in the New Task field."); else { if (document.forms[0].tasks.options.value == "tasks") document.forms[0].tasks.options[0] = null; var newTask = new Option(); newTask.value = document.forms[0].newtask.value; newTask.text = document.forms[0].newtask.value; var numTasks = document.forms[0].tasks.options.length; document.forms[0].tasks.options[numTasks] = newTask; document.forms[0].newtask.value = ""; } } function deleteTask() { var selectedTask = 0; var taskSelected = false; while (selectedTask < document.forms[0].tasks.length) { if (document.forms[0].tasks.options[selectedTask].selected == true) { taskSelected = true; break; } ++selectedTask; } if (taskSelected == true) document.forms[0].tasks.options[selectedTasks] = null; else window.alert("You must select a task in the list."); } function ascendingSort() { var newTasks = new Array(); for (var i =0; i < document.forms[0].tasks.length; ++i) { newTasks[i] = document.forms[0].tasks.options[i].value; } newTasks.sort(); for (var j =0; j < document.forms[0].tasks.length; ++j) { document.forms[0].tasks.options[j].value = newTasks[j]; document.forms[0].tasks.options[j].text = newTasks[j]; } } /* ]]> */ </script> </head> <body> <h1>To Do List</h1> <form action=""> <p>New Task <input type="text" size="68" name="newtask" /></p> <p><input type="button" value="Add Task" onclick="addTask()" style="width: 150px" /> <input type="button" value="Delete Selected Task" onclick="deleteTask()" style="width: 150px" /> <input type="button" value="Delete All Tasks" onclick="document.forms[0].task.options.length = 0;" style="width: 150px" /><br /> <input type="button" value="Ascending Sort" onclick="ascendingSort()" style="width: 150px" /> </p> <p><select name="tasks" size="10" style="width: 500px"> <option value="tasks">Tasks</option></select></p> </form> </body> </html> [CODE] HTML: Code: <!-- video player begin --> <div id="playerHolder"> <div class="player" id="playerDiv"> <div id="playerwidget"></div> <div id="adCompanionBanner" style="visibility:hidden;"></div> </div> </div> In firefox, I type Code: javascript:document.getElementById("player").sendEvent(''SEEK", 0); into the Address bar and hit enter. Why doesn't it work? How do I correctly "seek" a video. So I have made a website that you need a password to get into. The following javascript code works in Internet Explorer but, I need it to work in Safari also. Can anyone please rewrite this code, as simple as possible, to work in both Safari and Internet Explorer ? [CODE ]<!--// function mainpass() { if (pass.value=="password") {location="correct.HTML"}; else{location="wrong.HTML"}; } //--> [/CODE] Thanks in advance... |