javascript

Reason for using .prototype in Javascript

What are the technical reasons for using .prototype instead of declaring functions and members inside the object itself. It is easiest to explain with code examples. What are the advantages of using: RobsObject = function(data){ this.instanceID = data.instanceID; this._formButton = document.getElementById('formSubmit_' + this.i...

multiple jquery validators on one form

I'm using jquery.validate plugin and facing the following situation: <form id="myForm" ....> <input type="text" id="value1"/> <!-- Here is some code rendered from the partial --> <script type="text/javascript"> $(document).ready(function() { var validator = $('#myForm').validate({ rules: { ...

how could a <ul> element receive the focus event?

I'm running the following code to trace the tagName of every control that gets focus in an HTML document: $(function() { $("*").bind("focus", function() { console.log("tabbed " + this.tagName); }); }); When this runs I can watch the firebug console and see it trace tags like "A" and "INPUT" which I'd expect to receive ...

Detect all changes to a <input type="text"> (immediately) using JQuery

There are many ways the value of a <input type="text"> can change, including: keypresses copy/paste modified with JavaScript auto-completed by browser or a toolbar I want my JavaScript function to be called (with the current input value) any time it changes. And I want it to be called right away, not just when the input loses focus....

Javascript onKeyPress event not working ?

Why does this statement work with OnKeyPress event of Javascript in C#. txtPassword.Attributes.Add("OnKeyUp", "CheckPasswordStrength(\"" + txtPassword.ClientID.ToString() + "\",\""+ lblMessage.ClientID.ToString() +"\")"); this code is working correctly, my problem is that i want to run keypress event not keyup e...

Find end of FlashPlayer video using JS

Hey, I have a Flash player that I created with Moyea PlayerBox and I am trying to figure out how to find out when the video is done playing. I want to create a playlist kind of like ESPN does where you can do a check box for continuous play and if it is checked I want it to keep playing if not I want the user to be able to decide where ...

JavaScript: invoke function or call a property via reflection

Is there a way to call a function (or a property) on an object via reflection, in JavaScript? Lets say that during run-time, my code has already determined that objectFoo indeed has a property called 'bar'. Now that my code knows that, the next thing I want to do is invoke that. Normally i would do this: var x = objectFoo.bar. B...

Need to escape the quotes of a variable in MVC View to pass as a parameter to Javascript

Hi all, I have a MVC view in which I have to pass a string variable to javascript, but that string variable has single quotes in it ('). I am trying to do something like this <a onclick="JavaScript:AddressHandler.ProcessAddress('<%= homeAddress %>');" class="button-link">change</a> homeAddress has single ...

Adding an input name upon creation of new table row [jQuery]

I have an order form I had put together for a client, you can view it here. As you can see it creates a new row with 5 input fields (per row). Here's my problem, I have this form outputting the form in html format to the clients email for office use. I need to add a "unique name" for each input in the newly created row in order to pass ...

Automatically vertically scroll div contents looping

I am trying to find a simple way to have a div with just text in it automatically scroll the text vertically. I don't want to use a framework (though I do use Prototype, so if it is easier using Prototype then that is fine, but no Scriptalicious). I assume there has got to be a way to do this with a few lines of code, but I am not fami...

How do I sort this array in JavaScript?

How do I sort this array? [ {id : 1, start : 60, end : 120}, {id : 2, start : 100, end : 240}, {id : 3, start : 700, end : 720} ] UPDATE: So if my array looks like this, can I sort it based on start value? [{ 1:{start : 60, end : 120}, 2:{start : 100, end : 240}, 3:{start : 700, end : 720} }] ...

Why aren't these Dojo hover events working?

I'm new to Dojo (quite experienced in jQuery) for a project, and am working on adding/removing some classes that will change styles for main navigation links and drop-downs. Here is the code I've written: dojo.addOnLoad(function() { dojo.query('#primary-nav > ul > li > div').forEach(function(container) { var hoverToggles = doj...

Setting one object equal to another object with the assignment operator in Javascript

I'm coming to javascript from C background. In javascript, when I use the assignment operator to assign one object to another, does it copy the values from one to the another, or do they both now point to the same data?. Or does the assignment operator do anything in this case? function point_type() { this.x = 0; this.y = 0; } var ...

Need idea for implementing Yahoo Signup form's Name field in asp.net

I want to do the same functionality for first name Field and Surname field in the registration page of yahoo. When i clicks on textbox. Default text dissapears. And when i loses the focus from same textbox the default text appears again. Here is the yahoo registration page. How can i do this. I want to do xactly same functionality. Can y...

How do I convert this object to an array in JavaScript?

How do I convert testObj to an array? function MinEvent(event, width, left){ this.start = event.start; this.end = event.end; this.width = width; this.top = event.start; this.left = left; } var testObj = {}; for (var j=0; j<eventLists.length; j++) { var eve = eventLists[j]; var event = new MinEvent(eventList[j], width, lef...

watchPosition() vs getCurrentPosition() w/ setTimeout

I need to determine a person's location within 50m. I'm wondering if I should use navigator.location.watchPostion() or call getCurrentPostion() over and over again. watchPostion() is the proper W3C API for doing what I want, but practically, it seems to be overkill. Here's my code: var map = null; var marker = null; var layer = null;...

CSS Grid System for Forms (with Inline Labels)

This is a follow up to this question, I'm trying to have the same multi-column format but with inline labels instead of block labels, take the following mockup for instance: It's not very clear in the image but the name (label) + name (input) should occupy 50% (or near that) of the container width, the same goes for the email label + ...

How-to Make a JS Confirm Below leaving the page function

Hello, Google Docs, Gmail etc have this feature where if you try to leave a page that hasn't been saved it pops a dialog box with "confirm, Are you sure you want to navigate away from this page?" Is there a JQUERY plugin that will allow me to implement this kind of functionality? Thanks ...

need dynamic content on page using javascript

I need this page: http://winteradagency.com/mrw/index.php so that when you mouseover the different small images (actually a set of them) the text below changes from text into an image (which is a larger image of the smaller one) I used to use Fireworks for that sort of thing but I'm thinking that there must be an easier way using a comb...

Event not firing on dropdown list when disabled

This client side script is being added to buttons in our existing codebase. It basically shows a pop-up that the system is busy whenever a long running process is occuring. this works fine for buttons, however the btn.disabled = true line causes the SelectedIndexChanged event to never fire(when using it on a button, the click even still ...