I'm running into issues while trying to make some simple code to loop through and display different combinations of 3 colours.I want to show 3 boxes on screen and then loop through/increment each possible combination of colours.The problem with timeouts is although I can create a delay until the cycle on one level has finished before executing code to change the layer above it, this isn't enough - each level of loop has to increment just a single step after the layer "below" it completes a cycle. So I think I need some hybrid between nested for loops and timeouts (if such a beast exists).
The problems with the setTimeout and setInterval functions provided in Javascript are twofold. First, you can't call a local object method without losing your scope, and second, you can't pass objects to the function, since the function call is implemented as a string.
The Timer class solves these difficulties by employing a static array to store the parent object and function arguments until the function is called.
This class is provided as-is and pro bono, so go ahead and muck with it if you see things that could be done better.
Thanks to WA for giving me the idea for this (albeit indirectly)!
Updated 4/18/2003: Footprint decreased, minor code improvements. Updated 5/3/2003: Minor comment clarification; no code changes. Updated 5/10/2003: Minor code improvements. // The constructor should be called with // the parent object (optional, defaults to window).
function Timer(){ this.obj = (arguments.length)?arguments[0]:window; return this; }
// The set functions should be called with: // - The name of the object method (as a string) (required) // - The millisecond delay (required) // - Any number of extra arguments, which will all be // passed to the method when it is evaluated.
Timer.prototype.setInterval = function(func, msec){ var i = Timer.getNew(); var t = Timer.buildCall(this.obj, i, arguments); Timer.set[i].timer = window.setInterval(t,msec); return i; } Timer.prototype.setTimeout = function(func, msec){ var i = Timer.getNew(); Timer.buildCall(this.obj, i, arguments); Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec); return i; }
// The clear functions should be called with // the return value from the equivalent set function.
This is really more a IE issue than jquery but I am using jquery.
Has anyone used this setTimeouts method from the IXMLHttpRequest2 object from IE.
I want to monkey path jquery calls with this call below. I tried this and I still get a property method error even though the method seems to be available. Has anyone experienced this?
With this Javascript code, I get this error "Object does not support this property or method" error. I checked that the methods are available and I do a check that the method is there. Am I sending the wrong number of args? Has anyone used this?
I'm trying to add a function to an existing JS object without much success. The new function is included in a file of dynamically loaded JS (included using document.write), appended after the core JS script tag at runtime. This should be a simple task:
[Code]...
Adding extra script tags to the html source isn't an option either. There would be too many pages to think about. My new function must be dynamically loaded in with JS somehow. Is there anything else I could try?
I am working on an HTML project that displays a field with a number in the field by each day. What it does is start at 0 on day one. Each day it adds a 1 to the field. Day 2, the field would say 1, then day 3 would say 2, and so on. I am not sure how to approach this. This is also displayed in an HTML format. I want to to be automatic and change as the date changesI will also need a way to reset it back to zero if possible.
modifying an existing function which controls the highlighted states of a multi level js accordion menu. I have had to use javascript due to certain css elements not working in safari browsers.My problem is due to the multi level aspect as when a sub link is clicked, the parent link above it then deselects. I need the parent link to stay active when its sub links are clicked and only deselects when a link outside of that list is clicked upon.I understand the theory of adding a conditional statement but simply don't know how to apply it correctly within the functionHere is the existing function which tells a link to be active or selected:var Lst;
function CngClass(obj){ if (Lst) Lst.className='.topnav'; obj.className='selected';
I've got the following JS function that does a basic countdown to a specific date. I have a series of dates, and rather than change the date manually each time the previous one has passed, I'd like to automate it a bit and have it just read the date from an array, and use that date for the countdown. The check would be if the countdown'd date has already passed. Here's what I currently have:
<script language="javascript"> // date/countdown
function showDate () { var now = new Date(); var date = now.getDate(); var month = now.getMonth() + 1; var year = now.getYear();
currentDate = now.getMonth() + 1; window.status = month + "/" + date + "/" + year + " thisdomain.com ";
var roundCDiv = document.getElementById('roundC'); var showDate = month + "/" + date + "/" + year; //roundCDiv.innerHTML = showDate;
// countdown var nextDateB = new Date("October 30, 2005"); var diffB = nextDateB.getTime() - now.getTime(); var daysLeftB = Math.ceil(diffB / (1000 * 60 * 60 * 24)); var roundBDiv = document.getElementById('countdown'); //roundBDiv.innerHTML = daysLeftB + " days until ...; roundBDiv.innerHTML = daysLeftB; roundBDiv.innerHTML = daysLeftB + " "; }
I have been asked to make some changes to a form that uses Javascript for the form validation. There is a 'function' that contains the variables of the various form fields and then further code to raise 'alerts' if one of the fields on the form hasn't been filled in. My problem is that for some reason I am unable to add an extra variable to this code after the field of 'County' (this will hopefully make sense when you see the code / link...) and I am stumped as to why. I am able to add variables for all of the other required fields except for 'Postcode' after 'County'. This is the case for both forms. The link is here: [URL] and the code I am trying edit is below. The issues seems to be when I add && isPostcode() to this chunk of code:-
Code JavaScript: function checkAvailibility() { // re-calculate... calculate ();
I tried to create a function to reduce some in line code. However something is wrong with the function call getGenderChoice() because the code stops working. If I comment out getGenderChoice() and uncomment the lines that would be in the function it works properly. What would possibly be wrong with a function call that seems to follow function rules?
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Main</title>
I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? Code:
I am using a simple slideshow script. I have a div on top of the image that contains text. I'd like the slide to forward to the next slide in the slideshow when the user clicks on that div (#slideshow-caption). Here's the code with the .click call. If you see anything else funky with the script, let me know.
function slideShow(speed) { //append a LI item to the UL list for displaying caption $j('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
I'm having some trouble, so it's time I look to the community. I'm trying to add auto-rotation to a photo feature. It's pre-built, so I'm looking to just mod the code, rather than having to rebuilt the entire feature.Here is the existing code:
I was wondering if anyone could help me with an 'adding commas to decimals' problem. I have figured out that I need an 'addCommas' function but I can't seem to figure out where and how to call it!This is my code:
function ClearForm(form){ form.days.value = ""; form.nrstaff.value = "";
i've got a program that gets input from a user, and then stores it in a cookie. That bit is fine, what is a problem is that its just overwriting the data each time a new entry is made, i believed this to be something do do with it not being numbered entry's, so i added a number into the entry, but for some reason it wont add 1 to the number variable each time the function is called
I'm trying to write a function that takes a word and adds a space between each letter e.g space becomes s p a c e. I have written below but when I call the function it says the argument is not defined.
Code: function insertSpaces(string){ var currentCharacter; var resultString; resultString = '' //a line to loop through each charcther in the string agument for (var position = 0; position < string.length; position = position + 1){ // set current characther as the first charcter in the string and add a space currentCharacter = (string.charAt(position) + ' ') //store the currentcharcter and add followng characthers resultString = currentCharacter + resultString } return resultString }
I'm trying to add a click function to my object. The way i have it now in bold is how I saw someone else use it, it doesn't work. I tried using jquery's bind('click') and this.div.onclick but it runs the function right away upon instantiation.
How can i get this to run only when clicked?
function bubble(id,title,description,year,bubbleIcon,icon,source,length) {//art object from xml this.id = 'bubble' + id; this.title = title;
I'm trying to be able to click a row to highlight it on table controlled by tablesorter. I'm having a great deal of difficulty achieving this as nothing seems to make any difference.
I am adding the following after the call to tablesorter.
I have some jQuery.ajax() calls. It'is all the same but success function and I'd like get less code by taking all ajax calls in the same function.But I need one additional parameter I am using later in the success function, for instance.My actual code is like this:
I need to know how to add an event to a button. The specific issue is that I want to add an event which is a prototype function of a class. Consider the following as an example:
I have a form that is initially submitted by normal submit button, but after that I want it to resubmit on change(). I thought I'd be able to pick up the secondary change()s by adding a class to all of the inputs. However I now understand that won't work by default because the change() can't be attached to the class added by the the submit() as it didn't exist at the time, it was added by Jquery. I've since discovered on() but I'm now stuck on where to include it.
Here's the script so far: The submit() adds the 'stu' class, and then the change() tries to select it but can't <script> $(document).ready( function(){ $("#search_choices").submit( function(evt){ runSearch(); $("input").addClass("stu"); evt.preventDefault(); }); }); $('.stu').change( function(){ runSearch(); });
function runSearch(){ var sFor = $("#for").val(), sWhere = $('input[name=where]:radio:checked').val(); $("#search_results").load('search.php', { where: sWhere, treb: sFor } ); }; </script>