javascript

Pass a PHP string to a Javascript variable (including escaping newlines)

What is the easiest way to encode a PHP string for output to a Javascript variable? I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a Javascript variable. Normally, I would just construct my Javascript in a PHP file, ala: <script> var myvar = "<?php echo $myVarValue;?>"; </s...

Do Javascript properties calculate on each call?

Since length is a Javascript property, does it matter whether I use for( var i = 0; i < myArray.length; i++ ) OR var myArrayLength = myArray.length; for( var i = 0; i < myArrayLength ; i++ ) Thank you. ...

Call Web Services Using Ajax or Silverlight? Which performs best?

I'm building an ASP.NET AJAX application that uses JavaScript to call web services to get its data, and also uses Silverlights Isolated Storage to cache the data on the client machine. Ultimately once the data is downloaded it is passed to JavaScript which displays in on the page using the HTML DOM. What I'm trying to figure out is, doe...

Programmatically triggering events in Javascript for IE using jQuery

When an Event is triggered by a user in IE, it is set to the window.event object. The only way to see what triggered the event is by accessing the window.event object (as far as I know) This causes a problem in ASP.NET validators if an event is triggered programmatically, like when triggering an event through jQuery. In this case, the w...

JavaScript Table Manipulation

I have a table with one column and about ten rows. The first column has rows with text as row headers, "header 1", "header 2". The second column contains fields for the user to type data (textboxes and checkboxes). I want to have a button at the top labelled "Add New...", and have it create a third column, with the same fields as th...

Rendering order in Firefox

I am building the diagram component in JS. It has two layers rendered separately: foreground and background. In order to determine the required size of the background: render the foreground measure the height of the result render the foreground and the background together In code it looks like this: var foreground = renderForegrou...

How to render contextual difference between two timestamps in JavaScript?

Let's say I've got two strings in JavaScript: var date1 = '2008-10-03T20:24Z' var date2 = '2008-10-04T12:24Z' How would I come to a result like so: '4 weeks ago' or 'in about 15 minutes' (should support past and future). There are solutions out there for the past diffs, but I've yet to find one with support for future time diff...

Should I convert from MooTools to jQuery?

I have a fairly large codebase that depends on MooTools v1.11 and am about to convert to version 1.2. Since this is a pretty major overhaul, I've toyed with the idea of converting to jQuery. Anyone have advice on whether to update to jQuery or just stick with MooTools? I mostly use MooTools for Ajax, drag and drop, and some minor ef...

Is Http Streaming Comet possible in Safari?

By HTTP Streaming Comet, I mean the "forever iframe" / "forever xhr" variations that don't close the connection after data has been pushed from the server, as opposed to standard polling and long polling which close and resend a new request for every server push event. I looked at the dojo.io.cometd package and it seems they only have p...

Obtain form input fields using jQuery?

I have a form with many input fields. When I catch the submit form event with jQuery, is it possible to get all the input fields of that form in an associative array? ...

How do I reference an object dynamically?

In Javascript, I have an object: obj = { one: "foo", two: "bar" }; Now, I want do do this var a = 'two'; if(confirm('Do you want One')) { a = 'one'; } alert(obj.a); But of course it doesn't work. What would be the correct way of referencing this object dynamically? ...

How do I write content to another browser window using Javascript?

I've opened a new window with window.open() and I want to use the reference from the window.open() call to then write content to the new window. I've tried copying HTML from the old window to the new window by using myWindow.document.body.innerHTML = oldWindowDiv.innerHTML; but that's doesn't work. Any ideas? ...

How can I implement the pop out functionality of chat windows in GMail?

I'm not looking for a full implementation, I'm more interested in how they do it. I know they use GWT, but I'd like a more low level answer. Naively, I would start by thinking when you click the popout link they simply open a new window and copy content into it. There are lots of reasons why that won't work out well, so I'm wondering ...

In Flot, is it possible to eliminate or hide grid ticks without eliminating the corresponding label?

The Flot API documentation describes the library's extensive hooks for customizing the axes of a graph. You can set the number of ticks, their color, etc. separately for each axis. However, I can not figure out how to prevent Flot from drawing the vertical grid lines without also removing the x-axis labels. I've tried changing the tickCo...

Where can I find some good information about how the new canvas HTML element works?

I keep reading about how great this new Canvas element for HTML5 is and I see amazing demos done with just javascript and no flash. Where can I find some good information on how to some of these things myself? ...

How to remove only the parent element and not its child elements in JavaScript?

Let's say: <div> some text <div class="remove-just-this"> <p>foo</p> <p>bar</p> some text node here </div> some text </div> to this: <div> some text <p>foo</p> <p>bar</p> some text node here some text </div> I've been figuring out using Mootools, jQuery and even (raw) JavaScript, but couldn't get the idea how to do ...

Debugging javascript in IE?

Is there a better way to debug JavaScript than MS Script Editor? Like FireBug, but not like FireBug Lite. Thanks, ...

Looping over elements in jQuery

I want to loop over the elements of an HTML form, and store the values of the <input> fields in an object. The following code doesn't work, though: function config() { $("#frmMain").children().map(function() { var child = $("this"); if (child.is(":checkbox")) this[child.attr("name")] = child.attr("checked...

Do you know what may cause memory leaks in JavaScript?

Do you know what may cause memory leaks in JavaScript? I am interested in browsers: IE 7, FireFox 3, Safari 3 ...

javascript Image Resize

does anyone knows how to resize image proportionaly using javascript?, i have tried to modify the DOM adding attributes height & Width on the fly, but seems did not work on IE6 ...