javascript

django chain select

django-smart-selects is an elegant solution that enables Django developers to have chained select inputs in their forms. But as reported by developers in its list of issues, it does not work well when used in formsets. The javascript it renders is tied to the id of the "chained field" right in the model definition. How do you think thi...

How to create embeddable gadget with Javascript and PHP?

I'm programming in Javascript and PHP. I've created a simple website that allows to fill in a quizz and get result. Now I would like to give users opportunity to embed this quizz on their website. How to do this? It should work in some near manner like Google Gadgets, Adsense and that: that so when someone will put my html code (with JS?...

What is the best way to find out that access to the parent window has restrictions due to the same origin policy?

My current solution: function isAccessToWindowRestricted(w) { try { return !w.location.href; } catch (e) { return true; } } Any better ideas? Is there a 'legal' way without try-catch? ...

[Rails] reuse logic in views (javascript) and model

Hello, i have some logic to code in my model to calculate the number of business days between 2 dates input by the user. In my view i would like to display the same number of business days before the user submits the action... Is there a way to do this without duplicating code? I'd rather avoid an AJAX request (as it seems a bit overk...

Replacing div content using jquery in a jsp

So far I've been making an AJAX call to replace the content of a div with another page, using the following code: <script> function fetchContainerContent(url, containerid) { var req = false if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP") } catch (e)...

jQuery: How do I add a click handler to a class and find out which element was clicked?

Hi there, I have been using the following method for adding a click event to an id, I was wondering if i could do the smae with a class.... I have a number of items (which are created in a for each loop) and i need to be able to click them and then pickup which was clicked... here is my existing code $('submit-button').bind('click', su...

JQgrid and Java

Hi, can some one point to jqgrid + java web app solution or especially with populating the grid and sending the form back to server. there are several php examples but nothing on java. Help will be appreciated! ...

Is it possible to upload a whole folder instead of multiple files using Javascript?

Is it possible to upload a whole folder instead of multiple files using Javascript? If so, what is the approach. If there is no straighforward approach, is there any workaround to achieve the same? I have always been curious about this topic. Any insights will help. ...

WYSIWYG javascript editor usable for forum?

hello, i'm currently having a hard time finding a wysiwyg editor which can be integrated as editor for a forum. i've already looked at the famous ones like tinyMCE and CKeditor, but they don't work as how i would them expect to work. the problem: i want to have nested visible quotation. therefore it's -- imo -- required, that you use n...

Javascript behaving weirdly

Hi, the following function does not work as I thought it should have. For some reason, the loop breaks whenever one the the validate function returns false. Why is that? Here is my code : function validateGroup(input) { if (!input.value.match(/^[0-9]{0,2}$/)) { $(input).addClass("invalidField"); return false; }...

What's wrong with adding properties to DOM Element objects?

I've been looking for a straight answer for this (I can think of lots of possiblities, but I'd like to know the true reason): jQuery provides a .data() method for associating data with DOM Element objects. What makes this necessary? Is there a problem adding properties (or methods) directly to DOM Element Objects? What is it? ...

Onclick javascript not working properly in IE

Please excuse my ignorance I am not very familiar with Javascript and have been tasked with repairing a bug by a developer no longer at the company. The onclick works perfectly in FireFox, however in IE 7&8 (the only ones we test for), it appears to run through the onclick functions properly, then instead of the data being submitted to ...

Javascript window.scrollBy not working on particular page

window.scrollBy is not working on the following page http://www.resident.co.il/aspx/places.aspx?t=4&amp;a=1 Any idea what can be the problem ? ...

OAuth request token for an installed application

Hi all I'm trying to use/understand Google request token mechanism. I intend to use it for an application I've start to develop to access Orkut data using OpenSocial API. I read this document that explains the steps to obtain a token for an installed application. This document tells you to use the OAuthGetRequestToken method from Goog...

Is it possible to delete an entry from a JavaScript array?

Hi all, Is it possible to delete an entry from a JavaScript array? The entry in the list gets replaced with null when delete operator is used. data = [{pid:30, pname:abc}, {pid:31, pname:def}, {pid:32, pname:zxc}] delete data[1] becomes: data = [{pid:30, pname:abc}, null, {pid:32, pname:zxc}] FYI I'm getting this as json back from...

window.onerror does not work

I have some tricky AJAX code on a form, and sometimes it will fail (don't ask why, I can't get around it). When this happens, I need to trap the error, reset a hidden field indicator, and submit the form naturally so that the user does not have an unpleasant experience. I planned on using window.onerror to do this, but it is never firi...

rails jcrop + paperclip

hi all I have successfully implemented jcrop and paperclip to crop images by going to another page ie the crop.html.erb but i want to be able to do all cropping on my current page where i upload the image(s) in a popup div / dialog. so somehow i need to load this the crop.html.erb page into a popup div on click. Here is the code on t...

Init javascript Date object

Hi, I would like to retrieve a Javascript object Date for new year. I want to user new Date(); object and init it to the 2009-01-01 (it's for a countdown). Thanks ...

Find the longest common starting substring in a set of strings

This is a challenge to come up with the most elegant JavaScript, Ruby or other solution to a relatively trivial problem. This problem is a more specific case of the Longest common substring problem. I need to only find the longest common starting substring in an array. This greatly simplifies the problem. For example, the longest subst...

keydown EventListener not working in IE7 (Javascript)

Hello. I've written this code inside the HEAD tags of my HTML page. It works fine in FF, Chrome and Safaria, but doesn't in IE7. I would like to know how to fix it. <script type="text/javascript"> if ( window.addEventListener ) { window.addEventListener("keydown", function(e) { alert(e.keyCode); }, true); } </script> Thanks i...