javascript

How do I extract Google Analytics campaign data from their cookie with Javascript?

I'd like to be able to pull out the data stored in the Google Analytics tracking cookie with all the campaign tracking information using Javascript. It needs to work with the newer version of GA using ga.js, not urchin.js. I found a method that works with urchin.js but we don't use that for our tracking. Does anybody know how to extra...

Reversing order of elements

The following code rearranges elements by the attribute "amount". How can I alter this code so the items will be reversed? Thanks. var parent = $('#items'); var children = $('a', parent); children.sort(function(a, b) { return parseInt($(a).attr('amount')) - parseInt($(b).attr('amount')); }) $.each(children, function(i, child) { ...

How to organize OO js code in files? Local network application

I'm currently developing an application that will be run on local network in B2B environment. So I can almost forget about micro(mini?) optimizations in terms of saving bandwidth because Hardware Is Cheap, Programmers Are Expensive. We have a well structured Object oriented js code in the project and obviously lots of js classes. If all...

Reading Javascript Cookies from a subdomain...

On a subdomain -- a.test.com -- I'm trying to read the cookies set at .test.com. If I use document.cookie in JS, all i'm getting are the cookies from a.test.com. What is the syntax or route to read the cookies from .test.com? I'm pretty certain you can read up -- from sub domain to fqdn -- but you can not read down -- fqdn to sub doma...

Numbering in jQuery

How could I change the text below so that the text within it has a number appended to it. <div class="right">This is some text</div> <div class="right">This is some text</div> <div class="right">This is some text</div> So the code above would become, This is some text This is some text This is some text ...

Javascript show layer on page load

Getting an error when i use the following script to show a div when the page is loaded. <script type="text/javascript"> $(document).ready(function() { $("#friendslist").Show(); }); </script> It says $("#friendslist").Show() is not a function ...

Possible to select (inner)text of content that is loaded through a async (ajax) call?

I have a simple tree view that is loading child nodes through a ajah call to the server. I'm going to abbreviate the html but you should get the gist. <li id=1>Node 1</li> When this is expanded (by being clicked on) there will be a bunch of sub nodes loaded through a ajah call (they are not on the page to begin with): <ul> <li i...

How does this "days in month" function work?

function GetDaysInMonth(month, year) { return 32 - new Date(year, month, 32).getDate(); } Ok, I don't see what this is doing specifically, this part: new Date(year, month, 32).getDate(); I know what getDate() does, but then I looked up Date in JavaScript but in this particular example, I don't see why you'd pass 32 her...

jqPlot graph in accordion

I want to plot a graph within a jQuery accordion but it causes the graph to chopped and the scales to be displayed. Anyone got a fix for this? ...

comma operator returns the value of the second operand?

The links https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/Comma_Operator says The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand. and as an example for (var i=0, j=9; i <= 9; i++, j--) document.writeln("a["+i+"]["+...

Javascript clear

Is there a Javascript Clear function for a dropdownlist per say. ddlist.Clear(); or something of that sort? ...

Javascript: How to sort an array of records by values in one of the fields?

Hi, Suppose I have an array of records: [{a:0,b:0},{a:2,b:1},{a:1,b:2}] which I wish to sort in descending order of the "a" field in each record, and alert the sorted records as a new array (ie the new array would be [{a:2,b:1},{a:1,b:2},{a:0,b:0}]) - how would I go about this? I've tried a few approaches but am banging my head against ...

Shortcut for document.createElement("option") ?

My function clears out a dropdownlist and then re-populates it. Do I really need all this or is there a more concise way to do this? Meaning do I need to create a new document.createElement("option"); or is there a shortcut? for (blah blah blah) { objNewOption = document.createElement("option"); objNewOption.value ...

Hide <TR> tag based on Recordset NULL value

I am using a Microsoft SQL Server 2005 stored procedure to post records in an HTML table. In the HTML table, I have rows for the following fields: entry #, open date, description, and owner. Sometimes, the owner field in the db table will be NULL. When this happens, I have ASP response.write "N/A" in the HTML table row correspondin...

how to a make label message disable after 10 seconds

I have a form with two text boxes. Once I enter the data and click the save button, I get a message in label: indicating that it saved successfully. Then i am in the same form again, but when I click on the save button, I get a message telling me that it cannot be blank "as textbox value is empty this time" from the required field valid...

How can I prevent Firefox showing my extension's sidebar on startup?

If my own sidebar is left open when Firefox is closed, it is shown again on startup. I find this undesirable and would rather it remain hidden until opened manually. Is it possible to stop this happening? I tried adding this bit of code to my extension's initialisation function in order to close the sidebar if it does appear: toggleSid...

Boolean Concatenation? What's the real term for this pattern?

Please consider the following function body: var isValidated = true; $(selector1).each(function(){ //do validation with local f()... isValidated = f() && isValidated; }); $(selector2).each(function(){ //do validation with local f()... isValidated = f() && isValidated; }); $(selector3).each(function(){ //do validati...

Javascript regex in firefox extension

What could be going wrong here? The problem seems to be with the regex match statement. without it the alerts come, but as soon as I put it in everything goes quiet. Thanks so much! the wildcard is simply to help pinpoint the problem, it is NOT the objective, i do need regex. window.addEventListener("load", function() { myExtension.init...

How can I create a javascript class and access an internal collection using and index/name lookup?

I currently have this: function SystemCollection () { this.systems = []; this.getSystem = function (id) { for(var s in this.systems) { if(s.num == id) return s; }; return null; }; this.add = function (system) { this.systems.push(system); }; this.count = systems.length; }; In...

How do I show X number of LI from a list using javascript (no frameworks)?

I have a menu that is being populated by a server and I have no access to the server. So I am limited to doing this on the client side. Right now there is a dropdown menu on the navigation with 14 choices. The client wants to only show 3 of them. They're not using any frameworks like jquery or mootools, so I have to do this the old-f...