javascript

Declaring variables with this or var?

What is the difference between declaring a variable with this or var ? var foo = 'bar' or this.foo = 'bar' When do you use this and when var? edit: is there a simple question i can ask my self when deciding if i want to use var or this ...

Can't see images used in slideshow or other jQuery plug-ins in Internet Explorer 8

I am getting a weird error. I can see images in slideshow, lightbox, etc. in Firefox and Chrome but in Internet Explorer 8 there are no images. Something is wrong with JavaScript/jQuery I think. I am using jQuery 1.4.2, jquery.flow.1.2.min.js jquery.bgpos.js jquery.easing.1.3.js jquery.lightbox-0.5.min.js jquery.validate.js cufon-yui....

How to handle a clicked link in JavaScript?

How can I handle a link which doesn't have an id? It just has a classname like "classbeauty". Now I need to know if a user has clicked the link. If the link is clicked I just need to call alert("yes link clicked");. I don't know how to handle events in JavaScript. How can I do that? ...

Call javascript from MVC controller action

Can I call javascript function from MVC controller action (not from view page) and get return value? How? ...

Javascript: getting element in dom tree when mouseover

Hi, When using : document.onmouseover = function(e) {} Is there a property which gives me the element in the dom tree ? For example, I can set a style to e.srcElement But, how can I later access this element to (for example) reset its style ? And how can I know at which place in the dom tree it is ? I want to be able to situate it i...

Wait for function to finish before executing the rest

When the user refreshes the page, defaultView() is called, which loads some UI elements. $.address.change() should execute when defaultView() has finished, but this doesn't happen all the time. $.address.change() cannot be in the success: callback, as it's used by the application to track URL changes. defaultView(); function defaultVie...

search form in html/php via ajax

i've a search form wherein the database query has been coded in php and the html file calls this php file via ajax to display the results in the search form. the problem is, i would like the result to be displayed in the same form as search.html; yet while the ajax works, it goes to search.php to display the results. search.html: <!DOC...

JavaScript Price calculator script similar to this.

Does anybody know a script that is similar to this: http://simplythebest.net/scripts/DHTML_scripts/javascripts/javascript_49.html but only not with input fields, but with options, Yes / No. ...

Checking whether images loaded after page load

Determining whether an image has loaded reliably seems to be one of the great JavaScript mysteries. I have tried various scripts/script libraries which check the onload and onerror events but I have had mixed and unreliable results. Can I reliably just check the complete property (IE 6-8 and Firefox) as I have done in the script below?...

Retrieving data from a JSON sub array in javascript, where identifier starts with an integer

I must be missing something simple here, but I'm having trouble retrieving data from a JSON array response. I can access objects with identifiers that start with letters, but not ones that start with numbers. For example, I can access data.item[0].specs.overview.details But I can't access data.item[0].specs.9a99.details If anyone...

controlling css with javascript works with mozilla but not with webkit based browsers

Im having problems with a css text variable in this javascript with webkit based browsers(Chrome & Safari) but it works in firefox 3.6 importScript('User:Gerbrant/hidePane.js');//Special thanks to Gerbrant for this wonderful script function addGlobalStyle(css) { var head = document.getElementsByTagName('head')[0]; if (!head) { r...

javax script how to call a function in JavaScript from Java

Hi All, I'm trying to call a function in JavaScript via Java. This works fine when directly reading a script as a string but I'm using CompiledScripts. When I do this with a compiled script it gives me method not found if I also add bindings. Without bindings it works but of course the function fails because it needs the bindings. ...

capturing click events on web-browser scrollbars

Hi, is it possible to capture a click event on a scrollbar? I have some code where i am observing the click and mousedown events on the document. However, it seems that when I click on the scrollbar, the event is not captured. This leads me to believe that the scrollbars aren't really part of the document. (Assumption :-)) Is this a corr...

Need help to format the result page after searching

Hi, I have built a small text based search engine on ROR which will display relevant records having a specified search word in it.since few of the records has more than 1000 words i have truncated each result set to 200 characters.My views file search.html.erb looks like this <% @results_with_ranks.each do |result| -%> <% content_id...

How to pass an input value from a small form into a big form? (PHP, Javascript, URLs)

I have a Wordpress website that needs to display a 3rd party newsletter signup form. This sign-up form has lots of fields and takes up its own full page. I want to display a simple "enter email address, hit submit" form at the top of every page. When the user hits submit, it should take them to the full form, where their email address...

Why doesn't this jQuery snippet work in IE8 like it does in Firefox or Chrome (Live Demo Included) ?

I asked for help earlier on Stackoverflow involving highlighting spans with the same Class when a mouse hovers over any Span with that same Class. It is working great: http://stackoverflow.com/questions/2709686/how-can-i-add-a-border-to-all-the-elements-that-share-a-class-when-the-mouse-has $('span[class]').hover( function() { $...

Convert javascript string to an array

I'm retrieving an array of objects from a hidden html input field. The string I'm getting is: "{"id":"1234","name":"john smith","email":"[email protected]"},{"id":"4431","name":"marry doe","email":"[email protected]"}" Now I need to pass this as an array of objects again. How do I convert this string into array of objects? ...

CSS: achieving TWO-WAY infinite scroll with mouse drag

Hi, I'm trying to create an infinite scroll component. I'm using this site as a tutorial, but it seems that I can only get the infinite scroll on one way, because when I add elements to the leftmost side, the scrollLeft property auto-adjusts thus the page gets a quirky scroll, jumping instead of making a smooth movement. Is there any ...

Javascript cross-domain web request fails with Status=0?

EDIT: It's been pointed out below that this doesn't work because craigslist doesn't set an Allow-Cross-Domain header. OK, I'll buy that. Is there any other way to use javascript in firefox to download a page cross-domain then? Yes, I know the following code does not work in IE. I know IE expects me to use XDomainRequest() instead. I d...

Javascript Detect All Images (Including Asynchronous)

Is there a way in javascript to detect all images in a document, including those that may be loaded asynchronously (and maybe after the DOM is ready)? I'm looking to create a function that can detect if Google Analytics has been loaded by searching through the DOM looking for "__utm.gif". document.images doesn't seem to hold this image...