javascript

Elements order - for (... in ...) loop in javascript

Does the for...in loop in Javascript loops through the hashtables/elements in the order they are declared? Is there a browser which doesn't do it in order? The object I wish to use will be declared once and will never be modified. Suppose I have: var myObject = { A: "Hello", B: "World" }; And I further use them in: for (var item in...

Case insensitive string replacement in JavaScript?

I need to highlight, case insensitively, given keywords in a JavaScript string. For example: highlight("foobar Foo bar FOO", "foo") should return "<b>foo</b>bar <b>Foo</b> bar <b>FOO</b>" I need the code to work for any keyword, and therefore using a hardcoded regular expression like /foo/i is not a sufficient solution. What is the...

How can I determine which version of IE a user is running in JavaScript?

In some existing code there is a test to see if the user is running IE, by checking if the object Browser.Engine.trident is defined and returns true. But how can I determine if the user is running IE6 (or earlier) or IE7 (or later)? The test is needed inside a JavaScript function so a conditional comment doesn't seem suitable. Thanks ...

jQuery tooltip not working in IE

I am using the jquery tooltip and here is the code for it this.tooltip = function() { var xOffset = -10; var yOffset = -175; $("a.tooltip").hover(function(e) { this.t = this.title; this.title = ""; ...

How can I dynamically add an <object> tag with JavaScript in IE?

I have to add either an embed tag for Firefox or an object tag for Internet Explorer with JavaScript to address the appropriate ActiveX / Plugin depending on the browser. The plugin could be missing and needs to get downloaded in this case. The dynamically added embed tag for Firefox works as expected. The dynamically added object tag fo...

How can I dynamically create the source for a frame using javascript?

Suppose I have one html page with frames. The left frame is simply a list of links, which will be displayed in the right frame. Is it possible, using javascript, to generate the contents of the left frame when the page loads? ...

Remove empty elements from an array in Javascript

How do I remove empty elements from an array in Javascript? Is there a straightforward way, or do I need to loop through it and remove them manually? Thanks ...

Maintaining JavaScript Code in the <Head> after ASP.Net Postback.

As the title suggests, I am having trouble maintaining my code on postback. I have a bunch of jQuery code in the Head section and this works fine until a postback occurs after which it ceases to function! How can I fix this? Does the head not get read on postback, and is there a way in which I can force this to happen? JavaScript is:...

How good is Jquery's Backward Compatibility?

We have had issues with mootools not being very backward compatible and I was wondering if anyone has had any problems with Jquery because we are starting to use it and are now using a newer version for several new tools and I was wondering if it would be ok to get rid of the older version. ...

I want the simplest ajax form application

I want ajax application to process a simple form with textinput and submit button only , and without validation , i want to add this with a php script . I ask this because i don't know how to program with ajax or javascript . ...

Web page runtime errors

As I use the web, I regularly get runtime errors (usually javascript) being reported via popups. This can make for a really unsatisfying user experience on many otherwise excellent websites and also makes me wonder what functionality I am not getting access to. Why is this such a common issue? Is this down to a lack of testing or is it ...

Can I change the event queue priority in JavaScript?

I need a distinct sound to play when a error occurs. The error is the result of a problem with one of perhaps two hundred barcodes that are being inputted in rapid fire. The event queue seems to handle keyboard input (which the barcode scanner emulates) first, and playing of my sound second. So if the barcodes are scanned quickly, the...

How to highlight input text field upon clicking it in Safari?

I would like the value of the input text box to be highlighted when it gains focus, either by clicking it or tabbing to it. <html> <body> <script> function focusTest(el) { el.select(); } </script> <input type="text" value="one" OnFocus="focusTest(this); return false;" /> <br/> <input type="text" value="two" OnFocus="focusTest(this)...

Intellisense for AJAX and Javascript libraries in Visual Studio

I know about using a -vsdoc.js file for intellisense, and the one for JQuery is easy to find. What other javascript / AJAX / DHTML libraries have them and where can I find those files? Also, is there a document which outlines the specifications for -vsdoc.js files? ...

Javascript clarity of purpose

Javascript usage has gotten remarkably more sophisticated and powerful in the past five years. One aspect of this sort of functional programming I struggle with, esp with Javascript’s peculiarities, is how to make clear either through comments or code just what is happening. Often this sort of code takes a while to decipher, even if you ...

What is the event precedence in JavaScript?

What order of precedence are events handled in JavaScript? Here are the events in alphabetical order... onabort - Loading of an image is interrupted onblur - An element loses focus onchange - The user changes the content of a field onclick - Mouse clicks an object ondblclick - Mouse double-clicks an object onerror - An error occurs wh...

How does StackOverflow's 'tags' textbox autocomplete work?

I know they're using a jQuery plugin, but I can't seem to find which one they used. In particular, what I'm looking for is autocomplete with exactly the same functionality as SO's autocomplete, where it will perform an AJAX command with each new word typed in and allow you to select one from a dropdown. ...

jquery sortable except this one.

Need a way to allow sorting except for last item with in a list. Tried using the cancel option but it didn't work and I don't think that's what its for. I think a solution may be with events but would like your take on it. In practice the list is dynamically generated and relies on tag and relative referencing not id's for selecting...

How can I use JavaScript on the client side to detect if the page was encrypted?

Is it possible to detect, on the client side, whether the user is using an encrypted page or not? Put another way -- I want to know if the URL of the current page starts with http or https. ...

Debugging JavaScript errors in Internet Explorer on Vista with UAC enabled

Consider the following trivial HTML page that throws an error: <html><head><script> throw new Error('oops'); alert('should not reach here'); </script></head></html> The user I am logged into Vista with is a member of both the Administrators and Debugger Users groups. If I run Internet Explorer on Vista as an administrator (right ...