javascript

ajax request to different host

i have the following javascript in my webpage: var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://www.google.com', true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { alert('resp received, status:' + xhr.status + ', responseText: ' + xhr.responseText); } ...

How to make a lightbox?: concept

Imagine a lightbox with a beautiful picture inside it and a button somewhere near to navigate to the next picture... When the user clicks the next button, JS does like so: var Image = new Image(); Image.onload = getWidth; Image.onerror = getFailure; Image.src = "http://somewebsite.mr/pics/4.png"; Then when the picture is loaded, JS ...

How to load an image asyncronously with jQuery and how to know that the image loading is complete?

Well, the question is in the title. ...

Fade between pictures

Hi Whats the best way to fade between servel images? I can find a free user control the does it. So as i see it i have two choices 1) Try to incorporate some javascript, the java script is on this page http://slayeroffice.com/code/imageCrossFade/xfade2.html But how can it be done 2) Can I somehow encapsulate the Javascript in a asp.ne...

Combo box's default combination

I have two combo boxes, one for 'order by' and the other 'direction' (ascending, descending) I am wondering what is the simplest way to have a default combination... e.g order by A-Z I would want ascending by default and order by views I would want descending by default. I guess, onChange on the order combobox calling a JS function to ...

Convert a date to string in Javascript

I'm looking for a way to convert a Javascript Date object to a string. I'm converting my site from Ruby to server side Javascript, and I'm looking for something analogous to strftime in Ruby, C, and many other languages. I found plenty of simple scripts that do this kind of conversion, but I'd prefer not to include a custom implementati...

static progress bar as background of table cell

Does anyone know the best way to set the background of a row or cell as a 'progress bar'. For example if the 'percent used' cell value is '50%' the bar fills half the background of the row or cell. I am using PHP to generate the table, so maybe I could use a single colour image in the cell and set the width of the img. How would I get t...

How to getElementByClass instead of GetElementById with Javscript?

I'm trying to toggle the visibility of certain DIV elements on a website depending on the class of each DIV. I'm using a basic Javascript snippet to toggle them. The problem is that the script only uses getElementById, as getElementByClass is not supported in Javascript. And unfortunately I do have to use class and not id to name the DIV...

WordPress plugin tag not parsing in <script> block

I'm using the following code in one of my WordPress plugin files: else if($filetype == 'swf'){ print <<<EOT <script type="text/javascript" language="javascript"> jQuery(document).ready(function(){ var embed = '<div>[kml_flashembed movie="$img" /]</div>'; jQuery("#header").prepend(jQuery(embed)); }); </script> <style type="text/css"> #$h...

How to find the x,y coordinates of a rotated vector

Hi all, I found the best way of calculating the width and height of the bounding box of a vector post-rotation from a different stack overflow post. This worked great. My problem now is calculating the new x,y coordinates of the rotated vector's bounding box. Here is the my javascript. The newWidth, newHeight variables are correct -- the...

Google Maps Api: How to add a marker and speech bubble?

Hi there, I have managed to get a google map on my site using Javascript api of google maps.. and it works great... Can anyone tell me how i can add the Speech bubble and marker ... Pictured here... http://code.google.com/apis/maps/ Basically my site displays a simple map but its missing the marker for where office is and a speech bub...

Why does EcmaScript 5 strict mode go to such great lengths to restrict the identifier `eval`

According to the spec (Annex C), strict-mode code can't do pretty much anything that might assign any identifier with the name eval. I can understand that one might want to restrict use of the actual eval function, but I don't see what purpose is served by restricting use of the name? ...

injecting javascript to website using fiddler

Hi, I was thinking of using fiddler for the following purpose - I have a javascript based service I want to demonstrate to potential clients. In order to show them what their web site could look like if they install (i.e. include) my javascript, I want to set up fiddler on my pc, so that when fetching the client's website, the <script...

Sound effects in JavaScript / HTML5

I'm using HTML5 for its most noblest purpose: games, of course! The obstacle I've run into now is how to play sound effects. The game is a port of an old Macintosh game, and because of it's age, the requirements are few in number: Play and mix multiple sounds, Play the same sample multiple times, possibly overlapping playbacks Interru...

JavaScript: document.evaluate() problem

I am trying to get all objects but it doesn't work. var tmp = document.evaluate("//tr", document, null, XPathResult.ANY_TYPE, null); tmp.iterateNext returns me null; ...

adding values to a select box from a controller function (Ruby on Rails)

I have a Rails web application with a select box: <%= select_tag :foo %> I'm looking to write a function in the controller which would populate this select box with some values. What code would I need to write in order to do that? It's fine if the values are hard coded into the function. def populate # what goes here? end ...

Can anyone explain namespace in javascript with an example?

I am bit confused with namespaces of function in javascript. Can I have function with same names? Thanks ...

How to abstract the data away from the design in web pages?

What are ways of keeping the data separate from the design of a webpage, so that if you redesign the site, or you want to provide the ability for users to customize the layout, it would be really easy to do so. ...

How to know when image uploading is finished?

I want to use blockUI plugin for my project. I want to block UI during the uploading images, but i use simple image upload component (non ajax). Does any kind to identify when uploading images is finished and unbock UI? Thx ...

disabling default button or enter key in asp.et c#

I have a form where users scan in a barcode, the barcode reader automatically enters a carriage return in the value causing the form to submit since the browser chooses the first button as the default. How can I disable anything from happening when the enter key is pressed when entring a value in that textbox? ...