javascript

Sys is undefined

I have an ASP.Net/AJAX control kit project that i am working on. 80% of the time there is no problem. The page runs as it should. If you refresh the page it will sometimes show a javascript error "Sys is undefined". It doesn't happen all the time, but it is reproducible. When it happens, the user has to shut down their browser and r...

How do you execute a dynamically loaded JavaScript block?

I'm working on a web page where I'm making an AJAX call that returns a chunk of HTML like: <div> <!-- some html --> <script type="text/javascript"> /** some javascript */ </script> </div> I'm inserting the whole thing into the DOM, but the JavaScript isn't being run. Is there a way to run it? Some details: I can't contr...

Best practice: escape, or encodeURI / encodeURIComponent

When encoding a query string to be sent to a web server - what is the best practice to use from javascript: Use escape: escape("% +&="); OR use encodeURI() / encodeURIComponent() encodeURI("http://www.google.com?var1=value1&amp;var2=value2"); encodeURIComponent("var1=value1&var2=value2"); ...

How to determine if the user's browser can view PDF files

What's the best way for determining whether the user's browser can view PDF files? Ideally, it shouldn't matter on the browser or the operating system. Is there a specific way of doing it in ASP.NET, or would the answer be just JavaScript? ...

Prototype's Enumerable#pluck in F#?

In JavaScript, using the Prototype library, the following functional construction is possible: var words = ["aqueous", "strength", "hated", "sesquicentennial", "area"]; words.pluck('length'); //-> [7, 8, 5, 16, 4] Note that this example code is equivalent to words.map( function(word) { return word.length; } ); I wondered if somethi...

swfObject + scriptaculous Autocompleter = Fail

For some reason the combination of swfobject.js and script.aculo.us Ajax.Autocompleter on the same page causes the latter to fail. Autocompleter doesn't make its Ajax request. A separate Ajax control on the same page that uses Ajax.Updater doesn't seem to have the same problem. ...

How to get progress from XMLHttpRequest

Is it possible to get the progress of an XMLHttpRequest (bytes uploaded, bytes downloaded)? This would be useful to show a progress bar when the user is uploading a large file. The standard API doesn't seem to support it, but maybe there's some non-standard extension in any of the browsers out there? It seems like a pretty obvious feat...

Trouble having a modal dialog to open a secondary dialog

I have a modal dialog form which has some "help links" within it which should open other non-modal panels or dialogs on top of it (while keeping the main dialog otherwise modal). However, these always end up behind the mask. YUI seems to be recognizing the highest z-index out there and setting the mask and modal dialog to be higher tha...

Whats a good Javascript plugin color picker?

I make a lot of web applications and from time to time I need a color picker. Whats one that I can use like an API and doesn't require a lot of code to plug in? I also need it to work in all browsers. ...

Which JavaScript library is recommended for neat UI effects?

I need a JavaScript library that supports Ajax as well as help me in making simple and neat animation effects in a website I am working on. Which library do you recommend? ...

javascript (jquery) calendar plugin

Does any know of a good calendar (not datepicker, but a BIG browsable calendar) plugin for one of the major javascript frameworks. I'd prefer jQuery. ...

JScript debugging

I have a few scripts on a site I recently started maintaining. I get those Object Not Found errors in IE6 (which Firefox fails to report in its Error Console?). What's the best way to debug these- any good cross-browser-compatible IDEs, or javascript debugging libraries of some sort? ...

How do I programatically set the value of an select box element using javascript?

I have the following HTML select element: <select id="leaveCode" name="leaveCode"> <option value="10">Annual Leave</option> <option value="11">Medical Leave</option> <option value="14">Long Service</option> <option value="17">Leave Without Pay</option> </select> Using a javascript function with the leave code number as a param...

How do you reference .js files located within the View folders from a Page using Asp.net MVC

For example, if I have a page located in Views/Home/Index.aspx and a javascript file located in Views/Home/Index.js, how do you reference this on the aspx page? The example below doesn't work even though the compiler says the path is correct <script src="Index.js" type="text/javascript"></script> The exact same issue has been posted ...

How to skip fields using javascript?

I have a form like this: <form name="mine"> <input type=text name=one> <input type=text name=two> <input type=text name=three> </form> When user types a value in 'one', I sometimes want to skip the field 'two', depending on what he typed. For example, if user types '123' and uses Tab to move to next field, I want to skip it and go to f...

How to select consecutive elements that match a filter

Given this example: <img class="a" /> <img /> <img class="a" /> <img class="a" id="active" /> <img class="a" /> <img class="a" /> <img /> <img class="a" /> (I've just used img tags as an example, that's not what it is in my code) Using jQuery, how would you select the img tags with class "a" that are adjacent to #active (the middle f...

Are there any Parsing Expression Grammar (PEG) libraries for Javascript or PHP?

I find myself drawn to the Parsing Expression Grammar formalism for describing domain specific languages, but so far the implementation code I've found has been written in languages like Java and Haskell that aren't web server friendly in the shared hosting environment that my organization has to live with. Does anyone know of any PEG l...

Need javascript code for button press and hold.

I'd like a short smallest possible javascript routine that when a mousedown occurs on a button it first responds just like a mouseclick and then if the user keeps the button pressed it responds as if the user was continously sending mouseclicks and after a while with the button held down acts as if the user was accelerating their mousecl...

In Javascript, why is the "this" operator inconsistent?

In JavaScript, the "this" operator can refer to different things under different scenarios. Typically in a method within a JavaScript "object", it refers to the current object. But when used as a callback, it becomes a reference to the calling object. I have found that this causes problems in code, because if you use a method within ...

How to insert a text-like element into document using javascript and CSS?

I want to use javascript to insert some elements into the current page. Such as this is the original document: <p>Hello world!</p> Now I want to insert an element in to the text so that it will become: <p>Hello <span id=span1>new</span> world!</p> I need the span tag because I want to handle it later.Show or hide. But now problem come...