javascript

Why can't I use jQuery to fire an AJAX request from an unload event handler?

I have the following code, intended to log the event when a user closes a chat window: $(window).unload( function() { test(); }); function test() { alert("Hi"); $.ajax({ type: "POST", url: baseUrl + 'Index/test', data: "user_id=" + "Nisanth" + "& chat_id=" + 2, success: function(msg){ alert(msg...

Can't access public variable in public method?

Possible Duplicate: JS Object this.method() breaks via jQuery Hello, I'm playing around with creating classes in javascript but I don't think I really understand everything. Here is some (simplified) code I wrote (the .bind() comes from jQuery 1.4.1): function MyClass(size) { this.myList = new Array(size); for (var ...

Select tag / option tag trouble

So after about an hour wasn't able to find a good tutorial on how to use these tags and their ids,names, and values to achieve a decimal amount to finish summing my form. Simply put I have a select box and wish for it to return my option value and the amount of that option value. Heres the HTML <tr> <th colspan="4" class="label...

How to make GIF rotate when the tree is loading in Javascript

I have a tree that gets populated through the web service - this part is super fast, the part that's a bit slower is populating the tree...I have a gif rotating image that rotates while the service is loading. Since I use ajaxStop and ajaxStart trigger, the gif stops rotating after ajax request has completed, which is correct. However, b...

Tie a button to a javascript function

I have a button in html: <button id="MyButton" onclick="return DoSomething()">Click Me</button> Is it better to put the "onclick" property in the html or use javascript/DOM to attach a callback to the button click? ...

what's the jquery plugin that inserts text in a textbox, and it disappears upon focus?

what's the jquery plugin that inserts text in a textbox, and it disappears upon focus? ...

Turn Javascript String into PHP array

I'm not talking about JSON. I've got a program with the input being a javascript data structure in string format, something like this: $string = " var records = new Array(); records[0] = new Record('data1','data2',data3'); records[1] = new Record('data1','data2',data3'); records[2] = new Record('data1','data2',data3');"; Is there an e...

Ajax unit testing mocking using Jack

I am using Jack as JavaScript mocking library. http://github.com/keronsen/jack . I am also using qunit. I have following AJAX call in my javascript code which I am tring to write test for. $.ajax({ url: $('#advance_search_form').attr('action'), type: 'post', dataType: 'json', data: parameterizedData, success: functi...

Building JQGrid with Dropdowns and checkboxes

Hi, I have used jqgrids to display static values. But I have a scenario where I need to have checkboxes and dropdown values to be displayed in JQGrid columns. Depending upon whether I check or uncheck the checkbox. Any thoughts or comments on how to build jqgrids with Dropdowns and Checkboxes? ...

jQuery first child of "this"

I'm trying to pass "this" from a clicked span to a jQuery function that can then execute jQuery on that clicked element's first child. Can't seem to get it right... <p onclick="toggleSection($(this));"><span class="redClass"></span></p> Javascript: function toggleSection(element) { element.toggleClass("redClass"); } How do I refe...

High Frequency Ajax and MySQL Sleep Overload

I am currently working on a light php framework to use with some high request ajax for my site, and have run into an interesting problem that has me completely stumped. The ajax is for a series of notifications, so the javascript sends off an ajax request for new information every 30 seconds. This ajax is active on every page of the enti...

Check if $(this) has parents that have a class or id specified in an array

Hi again! First of all, after "testing" a while I have to say, stackoverflow is really really cool! To my question: I want to check if $(this) has not any parents that have a class or id specified in an js-array. By now I did this with "eval", but Andy E. just convinced me, that it is better to abandon "eval". However I have no clue h...

What's the situation with XSLT and XPATH in modern browsers?

I'm writing javascript code to traverse and manipulate deeply nested XML documents. With modern browsers, is there still a need for crossbrowser libraries like: sarissa ajaxslt As far as I know, without using one of these there won't be any XPath in IE with ActiveX disabled. And a simple wrapper is needed for both XSLT and XPath to d...

How to Make the RequiredField Validator visible

Using javascript or jquery, how can I make a Required Field Validator control (of ASP.NET) visible. If we check the viewsource of the Required Field valiator, we can see that the visibility is false initially. $("#spanReqFieldValidator").show() / fadeIn() wont work. Any thoughts ? From googling, I understand that jQuery has some issue...

How to Get the Title of a HTML Page Displayed in UIWebView?

I need to extract the contents of the title tag from an HTML page displayed in a UIWebView. What is the most robust means of doing so? I know I can do: - (void)webViewDidFinishLoad:(UIWebView *)webView{ NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"document.title"]; } However, that only works if javascript ...

Setting a preference at startup in firefox

Thanks to everyone in advance - I need to load a preference before any windows are loaded at startup. Below is some /component code I have been working with. The SetPreference method seems to fail when it is called (nothing executes afterwords either) - I am assuming because the resources that it needs are not available at the time of e...

Google Maps API V2: How to add markers which behave like the default google maps markers

I was wondering, with the free version... Can I plot the more default markers (from maps.google.com). The kind which when clicked, offer the option to enter driving directions and other tid-bits pulled from google's search of a business (eg: reviews). ...

Evaluating a string as a mathematical expression in javascript

If I have a string '1+1' is there a way, other than eval(string) to get the numerical value of it i.e. I want to turn '1+1' into 2. ...

JavaScript DOM dynamc Form from PHP

Hi! My MySQL Database Provides A List of Items (and integer IDs with them) in a <select> and a qty field for usage on my web form (with style display: none so it is hidden). But: I want the user to be able to select how many choices of this type he wants to enter in the form - how can I dynamically make multiple selects? Example: The p...

Get last clicked option in multiple select

On a page, I have a select (multiple) box with many options. Now I want to react on the last clicked item to display some data with ajax. As the "click" event on the option element does not work in IE, I currently use the "change" event. The problem is, that the "value" and the selectedIndex attribute point to the first selected item, ...