javascript

Convention for Javascript Domain Model Objects

Hi all, If I have to create a domain model object in C# I might do something like this: public class Person { Public string Name { get; set; } Public string Gender { get; set; } Public int Age { get; set; } } In Javascript, what is the convention for defining such objects? I'm thinking something like this: NAMESPACE.Pers...

Can someone explain this OOP javascript structure

Can someone explain this OOP javascript structure? I realize it is how you create 'objects' in javascript, just need some explanation on the notation and what it means: var vote = function(){ return { P1: function() { alert('P1'); }, P2: function() { alert('P2')...

jQuery mouseout firing when injecting child element

I'm trying to create a function which will add an overlay to a thumbnail image when you hover over it and remove the overlay when you leave it. Here is my HTML... <div class="thumb"><img src="i/testThumb.gif" /></div> And here is my jQuery... $('.thumb').live('mouseover', function(event){ if($(this).find('.overlay').length == 0){...

IE onPaste event using javascript not HTML

It seems that the only way to add an onPaste event to an input element is to use HTML: <textarea id="text_area" onpaste="on_paste" /> rather than being able to attach the event handler using javascript: document.getElementById('text_area').onPaste = function() { alert('I iz in ur textbox, pasting some text') }; The MSDN website say...

Javascript function: nothing executes after a for(x in y) loop?

I can't seem to find the answer to this anywhere... I have a function that needs to set the bg color of two tables. Only the first table in the function is being affected. Is only one for loop allowed in a function? ...or is the 1st for loop maybe never exiting? I can pretty much work around this by creating multiple functions but I re...

Automatic feedback on JavaScript error

Is there a way to get an automatic feedback if an error (even syntax errors) occurs when running a JavaScript on the client side? I was thinking of something like this: <script src="debugger.js"></script> <script> // some script with an error in it </script> And every time the debugger notices an error it sends a feedback to the ...

How to retrieve the size of a file before uploading it?

I have an file input tag in my web app. I'd like to check that the file isn't too big before sending it to the server. Of course, I still have validation server side. Is there any way to do this with JavaScript? It must work in IE7+ and FF3+. Thank you. EDIT: somefileinputobject.files[0].filesize works in FF, but not IE. ...

How to make TinyMCE work inside an UpdatePanel?

I'm trying to do something that many people seem to have been able to do but which I am unable to implement any solution. The TinyMCE control works pretty well in an asp.net form until you enclose it with an UpdatePanel, which then breaks after postback. I have tried some fixes like the RegisterClientScriptBlock method, but am still unsu...

Where do you include the jQuery library from? Google JSAPI? CDN?

There are a few ways to include jQuery and jQuery UI and I'm wondering what people are using? Google JSAPI jQuery's site your on site/server another CDN I have recently been using Google JSAPI, but have found that it takes along time to setup an SSL connection or just to resolve google.com. I have been using the following for Google:...

When I add an option to a select the select gets narrower.

Inherited an app with a page that has a link that calls the javascript function addValueClick(), when I do this a dialog box pops up, I type in some text, and then the text gets put in the select box. Every time a new option is added to the select it gets about 5 pixels narrower. I can't figure out why this is happening, but it only hap...

What is the best way to measure Client Side page load times?

I'm looking to monitor the end user experience of our website and link that with timing information already logged on the server side. My assumption is that this will require javascript to to capture time stamps at the start of request (window.onbeforeunload) and at the end of loading (window.onload). Basically this - "Measuring Web appl...

Is this the best way to create an 'All' tab using jQuery tabs?

I have created an interface using jQuery UI Tabs, however one of my requirements was to have an 'All' option that would display the contents of all the pages in the tab group at the same time down the page. My tabs are being generated dynamically from PHP and I am giving each tab button an id so that the result looks like follows: <li ...

Safest way to make sure a HTML button does not send any information to the server

I'm working on a javascript app that has a form with a button that processes inputs in the browser. It is important that the data never accidentally get sent to the server when the button is pushed. Situations where this might happen is the browser may not have javascript enabled or the DOM implementation may have a bug where the click...

How can a object self destruct on an event, in javascript?

I have this function, to create a DIV on-the-fly. But now, I want to destroy this object on onclick event, but I just don't know how. function creatediv(id) { var newdiv = document.createElement('div'); newdiv.setAttribute('id', id); newdiv.onclick=function(){this=null;}; //bad function document.body.appendChild(newdiv...

Dynamically loaded User control ID and javascript

I have a host page that dynamically loads multiple instances of the same user control by assigning different IDs. After the UC loads, I will need to use JS to get a reference to a textbox. For this, I need the User control Client ID. I do have access to the UC Client ID on the server side and can set a hidden form variable with this inf...

Select all HTML checkboxes

I have a small list of checkboxes (see below), and I noticed I can use an input element with type="reset" and it will uncheck all the boxes. I know using the input would be better than an "onClick" event of the link, because I wouldn't be relying on JavaScript, but for this example I have both. <a onclick="javascript:document.myList.re...

Suggestions for information visualization using flash or javascript

I remember looking at a couple information visualizations tool a while back. One was written in flash and the other in Javascript. They both allowed you put notes in "bubbles" and then link them to other "bubbles". Clicking on an existing bubble brought it to the front and rearranged others around it. The JS one was particularly inter...

How do I make a callable JS object with an arbitrary prototype?

I'm looking to make a callable JavaScript object, with an arbitrary prototype chain, but without modifying Function.prototype. In other words, this has to work: var o = { x: 5 }; var foo = bar(o); assert(foo() === "Hello World!"); delete foo.x; assert(foo.x === 5); Without making any globally changes. ...

jQuery and Auto-populat selects

Hey, I have a simple page where I can select a client, then once I chose that autopopulate to the projects that belong to the client. I am using PHP/MySQL to pull the results. I took at a look at this: http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ but I think that starts with both fields on the page. ...

Setting focus to an swf using JS

How do I set the focus on a SWF embedded in a page using Javascript? I tried to use the usual method but it doesnt seem to work... ...