JavaScript - This Function Stops My Clock Working
I have a clock that works onbodyload, however using the below function on the same page, stops my clock even coming up, any help would be great.
Code: <script language="JavaScript"> var HAS_EXPIRED = 'Time has Expired!'; var IS_NONE = 'None'; function secondCountdown(s){ if(s){ var timeleft = document.getElementById('timeleft').innerHTML; if((timeleft == HAS_EXPIRED) || (timeleft == IS_NONE)) return false; timeleft = timeleft.replace('<font>', ''); timeleft = timeleft.replace('</font>', ''); var time = timeleft.split(":"); var secs = time[2] * 1; var mins = time[1] * 1; var hrs = time[0] * 1; secs += (mins * 60) + (hrs * 3600); secs -= 1; if(secs <= 0){ document.getElementById('timeleft').innerHTML = HAS_EXPIRED; return false; } else { hrs = Math.floor(secs/3600); secs -= (hrs * 3600); mins = Math.floor(secs/60); secs -= (mins * 60); if(hrs < 10) hrs = '0' + hrs; if(mins < 10) mins = '0' + mins; if(secs < 10) secs = '0' + secs; document.getElementById('timeleft').innerHTML = hrs + ':' + mins + ':' + secs; } } setTimeout('secondCountdown(true)',1000); } bootloaderAdd('secondCountdown()'); bootloaderOn(); </script> Similar TutorialsHey guys, so I'm trying to make a single function that will check to make sure the e-mails in both fields match AND to make sure the e-mail is in proper format. Strangely, with both if statements included the form will return no messages at all. If I comment out the if statement checking for proper format, the if statement to check for matching e-mail works just fine. I want this all to be in one function because I'm wanting it to be executed onSubmit with the form. Let me know what you guys think, any help is greatly appreciated: Code: <html> <head> <script type="text/javascript"> function verifyEmail() { var x = document.forms["emailForm"]["enterEmail"].value; var y = document.forms["emailForm"]["confirmation"].value; var atpos = x.indexOf("@"); var dotpos = x.lastIndexOf("."); if (x != y) { var msg = "The email addresses entered do not match, please enter matching email addresses"; document.getElementById("error").innerHTML = msg; return false; } if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 > = x.length) { var msg = "Improper e-mail format"; document.getElementById("error").innerHTML = msg; return false; } else { return; } } </script> </head> <body> <form name="emailForm" onsubmit="return verifyEmail();" method="post"> E-Mail Address: <input type="text" name="enterEmail"> Confirm E-Mail Address: <input type="text" name="confirmation"> <input type="submit" value="Submit"> <span id="error"></span> </form> </body> </html> My bad if this was answered somewhere else. I did search the forums but was unable to locate an answer (It is kind of a specific question) I have an odd problem. I have the following clock script: Code: function Clock() { var today=new Date(); var h=today.getHours(); var m=today.getMinutes(); var s=today.getSeconds(); // add lead zeros to numbers less than 10 h=checkTime(h); m=checkTime(m); s=checkTime(s); document.getElementById('Clock').innerHTML=h+":"+m+":"+s; t=setTimeout('Clock'), 500); } function checkTime(i) { if (i<10) { i="0" + i; } return i; } Loaded at the page load and assigned to a div: Code: <body onLoad = "Clock();"> <!--the clock--> <div align = "right" id = "Clock"></div> With this style applied: Code: #Clock {font-size: 30pt; position: fixed; top: 0px; right: 0px; background: #ffffff; z-index: 3; } The problem I've run into is this: In Chrome, whenever I scroll down, even by just one tap/click of the down arrow, the clock stops updating the time in, pardon the pun, real-time. But the second I scroll completely to the top of the page, it goes back to counting. I tested in the current (as of Nov 20th 2010) versions of FireFox, Opera and IE9 and the only browser that seems to produce this problem is Chrome. Any ideas? I have a simple function to display an image when called, but if I try to rewrite the function to take the image as an argument, it stops working. I've looked at other function examples on the web but can't figure out what I am missing. Can anyone help? works: Code: <html> <script language="JavaScript"> var ImagePlusSign = '<img src="plus.jpg" name="slide" width="65" height="50"/>'; function FlashImagesThenWait() { document.getElementById("first").innerHTML = ImagePlusSign } setTimeout(FlashImagesThenWait, 1500); </script> <body>Hello. <div id="first"> </div> </body> </html> does NOT work : Code: <html> <script language="JavaScript"> var ImagePlusSign = '<img src="plus.jpg" name="slide" width="65" height="50"/>'; function FlashImagesThenWait(z) { document.getElementById("first").innerHTML = z } setTimeout(FlashImagesThenWait(ImagePlusSign), 1500); </script> <body>Hello. <div id="first"> </div> </body> </html> ok so Code: document.write("Goodbye!"); works but I put ^ that inside a function Code: function SayHello () ( document.write("Goodbye!"); ) and it stops working? I know the function call works because when I place some code to display an image in SayHello function, it displays the image. My website is all up and running and I decided to put a new image viewing script on, I already had a revolving image script showing all my previous work before but the latest script has totally stopped the previous from working. You can view what I mean at www.actioncomputing.co.uk I am using 2 scripts both available on Dynamic Drive they are Lightbox image viewer 2.03a Ultimate Fade-in slideshow (v2.1) If anyone can tell me why this is I would be extremely gratefull. I'm trying to create a navigation bar with four elements. If the element is currently selected it will have a "red" background image, if it is one of the other 3, it will have a "black" background image. my four tabs are 'timetable, homework, notifications and sport' I tried making 8 functions like the 2 below Code: function setTimeRed() { document.getElementById("time").style.ClassName = 'timetable_r'; } function setTimeBlack() { document.getElementById("time").style.ClassName = 'time_r'; } And then four blocks like this: Code: function changeTimeButton() { var timePath = new String(); timePath = document.getElementById("timetable").style.backgroundImage; if(timePath == "url(assets/img/tabs/time_black.png)" || timePath == "") { setTimeRed(); setHomeBlack(); setNotiBlack(); setSportBlack(); } else { } } finally, my html has this: Code: <div id="tabbar"> <ul id="tabs"> <a href"#" onclick="changeTimeButton()"> <li id="timetable" class="time_b"> <p>Timetable</p> </li> </a> <a href"#" onclick="changeHomeButton()"> <li id="homework" class="home_b"> <p>Homework</p> </li> </a> <a href"#" onclick="changeNotiButton()"> <li id="notifications" class="noti_b"> <p>Notifications</p> </li> </a> <a href"#" onclick="changeSportButton()"> <li id="sport" class="sport_b"> <p>Sport</p> </li> </a> </ul> </div> It works once then does nothing. Why, and how would I go about fixing this?? Please help! Hi all, I've found a small script that displays the current time. The only problem is that it only works with IE and I'd like to make it work on all browsers (or at least Mozilla) Would you mind helping me ? Note: I'd like to keep the code using the "span" tag Here's the html code (to show the way I call the script): Code: <html> <head> <SCRIPT language="JavaScript" SRC="clock.js"></SCRIPT> </head> <body onLoad="clock()" bgcolor="#ECEDF3"> <font face="Verdana" size="1" color="#88A6C0"><span id="pendule" ></span> </body> </html> and here's the script I use (It's an external script that I called clock.js): I believe the declarations are OK and the problem comes from "document." I know there are differences the way IE and other browsers manage scripts but I'm not enough experienced to find all variants. Code: <!-- Begin function clock() { if (!document.layers && !document.all) return; var digital = new Date(); var hours = digital.getHours(); var minutes = digital.getMinutes(); var seconds = digital.getSeconds(); var amOrPm = "AM"; if (hours > 11) amOrPm = "PM"; if (hours > 12 ) hours = hours - 12; if (hours == 0) hours = "00"; if (minutes <= 9) minutes = "0" + minutes; if (seconds <= 9) seconds = "0" + seconds; dispTime = hours + ":" + minutes + ":" + seconds + " " + amOrPm; if (document.layers) { document.layers.pendule.document.write(dispTime); document.layers.pendule.document.close(); } else if (document.all) pendule.innerHTML = dispTime; setTimeout("clock()", 1000); } // End --> Any idea about what's wrong ? Thank you for your help Gino Hey everyone, I have a page where I call two external javascript files, and they work perfectly when I have all the files on my desktop. But once I transferred all the files into a folder, the scripts stop working. What's going on?! EDIT: Nevermind. I just forgot to relocate my jquery file! I found this script, and it works great: Code: <script type="text/javascript"> function disable(element) { var input = document.getElementById(element).getElementsByTagName("input"); for(var i = 0; i < input.length; i++) { input[i].setAttribute("disabled","true"); } } </script> I tried to make the inverse by simply reversing the setAttribute() like so: Code: <script type="text/javascript"> function enable(element) { var input = document.getElementById(element).getElementsByTagName("input"); for(var i = 0; i < input.length; i++) { input[i].setAttribute("disabled","false"); } } </script> But that didn't do it. Can someone show me why, and how to fix it? Here's the sample form which I'm trying to test it on: Code: <form> <input type="radio" name="test" onclick="disable('D1')" /> disable<br/> <input type="radio" name="test" onclick="enable('D1')" /> enable<br/> <fieldset id="D1"> <input class="" type="text" value="test value1" /><input class="" type="text" value="test value2" /><br/> <input class="" type="text" value="test value3" /><input class="" type="text" value="test value4" /><br/> <input class="" type="text" value="test value5" /><input class="" type="text" value="test value6" /><br/> </fieldset> </form> Edit: The ultimate goal which I'm working toward now (step by step =) is to have a form more like: Code: <form> <input type="radio" name="test" onclick="disable('D1')" /> <fieldset id="D1"> <input class="" type="text" value="test value1" /><input class="" type="text" value="test value2" /> </fieldset> <input type="radio" name="test" onclick="disable('D2')" /> <fieldset id="D2"> <input class="" type="text" value="test value3" /><input class="" type="text" value="test value4" /> </fieldset> <input type="radio" name="test" onclick="disable('D3')" /> <fieldset id="D3"> <input class="" type="text" value="test value5" /><input class="" type="text" value="test value6" /> </fieldset> </form> And have the fieldsets enable and disable according the selection of the radio buttons. Also, the fieldsets (and their ID's) will be dynamically generated via PHP Thanks-a-bunch, ~ Mo OK so I am trying to put the following output together 2: 2 3: 3 4: 2,4 5: 5 6: 2,3,6 7: 7 8: 2,4,8 9: 3,9 10: 2,5,10 So I am looking for factors of numbers. User inputs a minimum and maximum and the function runs until it hits the max number. In between it is going to write out all of the factors for each line number. Here is function so far and it is NOT working function allFactors(num1,num2,outputDiv){ var min = parseInt(document.getElementById(num1).value); var max = parseInt(document.getElementById(num2).value); var output = ""; var start = 2; for (var i = 1; i <= max; ++i) { output += i+":" if (min/start == Math.round(min/start)){ output += start } else { ++start } }"<br />" addToDiv(outputDiv, output); } I am having trouble getting my function to work here is what I have so far Code: <script type="text/javascript"> // script element to add the votes.js function totalVotes(votes1){ // script element that will calculate the array ****var total = 0; ****for (var i = 0; i < votes1.length; i++) { *******total = total + votes1[i]; ****} ****return total; } </script> Can anyone see whats wrong? when i run it i still get nothing Hi, What I did is not working. Using coldfusion. Have cfselect object (id="Decision") with 3 values - Select; Approved; Denied. Have two input buttons, Request Approved (id="approved") and Request Denied (id="denied"). The Approved is visible but disabled. The Denied is not visible. The user needs to select from "Decision" either Approved or Denied before he/she can submit. So when user selects Approved from drop-down I want to enable Request Approved submit button. If user selects Denied from drop-down I want the disabled Request Approved button to not be visible and the Request Denied button to be visible and enabled for submission. The respective buttons will be directed to their appropriate actions. Code: <script type="text/javascript"> var decide = function() { var choice = document.getElementById("Decision"); var apprvd = document.getElementById("approved"); var deny = document.getElementById("denied"); if (choice.value == "Approved") { deny.style.disabled = "disabled"; deny.style.visibility = "hidden"; apprvd.style.disabled = false; apprvd.style.visibility = "visible"; } if (choice.value == "Denied") { apprvd.style.disabled = "disabled"; apprvd.style.visibility = "hidden"; deny.style.disabled = false; deny.style.visibility = "visible"; } } </script> Nothing happens - any suggestions why not? Thanks - John Hello, I am new to this forum stuff so please bear with me. This is the code I am using. Code: <script type="text/javascript"> function ReadForm(obj1) { "use strict"; var amt = obj1.amount.value; obj1.amount.value = amt - (amt / 6.6); } </script> The value (obj1) is 99 It is supposed to return a value of 84 and I keep getting 99 DId I do something wrong ? I am trying to pass a value to another function, seems to work with the other function i have but not this one? any reasons why this wont work? Code: /* ---------------------------- */ /* XMLHTTPRequest Enable */ /* ---------------------------- */ function createObject() { var request_type; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ request_type = new ActiveXObject("Microsoft.XMLHTTP"); }else{ request_type = new XMLHttpRequest(); } return request_type; } var http = createObject(); /* -------------------------- */ /* SEARCH */ /* -------------------------- */ function autosuggest(q,f,r) { alert(q+' '+f+' '+r); // q = document.getElementById(var f).value; // // Set te random number to add to URL request nocache = Math.random(); http.open('get', 'ajax_search_for_airport.php?q='+q+'&f'+f+'&r'+r+'&nocache = '+nocache); http.onreadystatechange = autosuggestReply(r); /* this line is not working as expected, it kicks up an error Message: Type mismatch Line: 26 Char: 1 Code: 0 i am wanting to pas the value of r to the other function. */ http.send(null); } function autosuggestReply(r) { if(http.readyState == 4){ var response = http.responseText; e = document.getElementById(r); if(response!=""){ e.innerHTML=response; e.style.display="block"; } else { e.style.display="none"; } } } function fill(r,fieldid,resultsid) { e = document.getElementById(fieldid); e.value=r; document.getElementById(resultsid).style.display="none"; } hello, i have a form validator that works fine in chrome, safari, firefox...but not IE 8.. i'm pretty new at javascript... any help is appreciated Code: function detect() { if(navigator.cookieEnabled == false) { alert('You must enable cookies in your browser!'); return false; } if(document.add.color.value == "-Select Color-") { alert('Please select a color!'); return false; } if(IsNumeric(document.add.quantity.value) != true) { alert('This must be a number!'); return false; } if(document.add.quantity.value == 0) { alert('You must add at least one item!'); return false; } } and the html Code: <form name='add' onSubmit='return detect();' method='POST' action='process.php'> I've been working on RSA encryption using javascript and php for quite some time but i'm not able to do it properly. i'm using the standard RSA.js,BigInt.js and Barrett.js javascript files for the javascript part but the thing that i have noticed is the public exponent is always 10001 or 3 . only then the function works. but the problem is the php file generates a comparatively larger public key exponent. if i use that in the javascript function it crashes. is there anyway out of this ?
Hi This is for a class project, for some reason only the first part is working. The (sales*.20) and all of my else if are not. Kind of stuck on this. Code: <script type="text/javascript"> function bonus() { var sales var excellent var good var fair var poor sales= document.workBonus.txtSales.value; sales= parseInt(sales); excellent= document.workBonus.chkExc.value; good= document.workBonus.chkGood.value; fair= document.workBonus.chkFair.value; poor= document.workBonus.chkPoor.vaule; if (sales && excellent) { alert(sales * .20) } else if (sales && good) { alert(sales * .10) } else if (sales && fair) { alert(sales * .05) } else if (sales && poor) { alert(sales * .01) } } </script> I've been stuck on a piece of code for awhile. I have two items but they won't run at the same time only one will work: Code: function loadProductK ( prSrc, imgSrc, prDesc, pr$, prStock, prAnchor, rank ) { var product ='<div class="productDiv" id="'+prAnchor+'"><img src="'+imgSrc+'" width="150" height="150" title="'+prDesc+'"/><div class="productname">'+prDesc+'</div><div class="product$">€'+pr$+'</div><div class="productstock">'+prStock+'<div class="productvisit"><li onclick="loadPage("'+prSrc+'")">Check product >></li></div></div>' var productpage = document.getElementById("imgLoad") productpage.innerHTML=product loadProductK ('page/p/bead1.html','page/i/bead1.jpg','Round Bead','1,22','In Stock','Bead1','1' ) loadProductK ('page/p/Bead2.html','page/i/Bead2.jpg','Three Round Beads','6,99','In stock','Bead2','2' ) } Now i need the function loadProductK to work for both of the loadProductK's as seen below. Really need some help on this one. I am creating a weather widget for the iphone. The program creates an xml request for a weather feed and then parses the response. Depending on the response different information is displayed. A different icon for each weather pattern. I have all of this working so far. What I want to integrate is the option to refresh the weather when a user taps on the icon. Here is my code: Code: document.getElementByID("weatherIcon").innerHTML="<img src=\"Icon Sets/"+iconSet+"/"+MiniIcons[obj.icon]+iconExt/" border=2 onclick=\"refresh();\">" Code: function refresh() { weatherRefresherTemp(); } I know that the function refresh works because it is called from another function that allows the refresh to happen automatically every 30 min. However, wanting to integrate an option to manually refresh I am trying to do it this way. The code never seems to fire, nothing happens. I've added the border option for testing and don't even see that. I've been using a javascript editor and I do not get any errors. Any suggestions would be greatly apprectiated. |