javascript

Browser detection versus feature detection

I’m going to play a devil's advocate for moment. I have been always wondering why browser detection (as opposed to feature detection) is considered to be a flat out a bad practise. If I test a certain version of certain browser and confirm that that certain functionality behaves is some predicable way then it seems OK to special case it....

Does anyone know of a good pre-existing javascript date range drop-down?

I'm looking for a javascript drop-down for a date range that allows the user to select start and end dates from a single form field, similar to what exists in the Google Analytics UI. I've found a lot of pre-existing javascript for two separate form fields, or for using a calendar to choose a single date, but nothing that accomplishes...

Text input readonly attribute not recognized in IE7?

I am setting readonly="readonly" (in other words, true) via javascript: document.getElementById("my_id").setAttribute("readonly", "readonly"); This is having the intended effect (making the field no longer editable, but its contents are submitted with the form) in FF, Safari and Chrome, but not for IE7. In IE7 I can still modify the c...

How to disable Struts validation under certain conditions

The problem I have is that I need to disable struts validation when selecting certain conditions that will leave input boxes disabled and blank. Leaving these inputs empty causes the validation to fail which is not what I need ...

JavaScript event for when image 'src' attribute is changed?

I have a function resizePreview() that will resize an image in a jQuery dialog box if the image is too big. This image can be changed by the user. My code goes something like this: $('#imagePreview').attr('src', newImageSrc); resizePreview(); resizePreview() uses $('#imagePreview').width() and .height() to get the dimensions and res...

Building Dynamic UI with C#?

I need to expose some input fields based on what properties I find for particular types in an assembly. I'm not sure how common an approach like that is. Perhaps there are easier ways. Maybe on the client side instead of server. If anyone knows of a good way of doing something like this, I would appreciate the help. Create input contr...

JQuery UI slide effect creates a new line

I want to enable an effect on my web app where a user clicks an "Edit" icon and a text box elegantly slides out horizontally immediately to the right of the icon. Currently it is sliding out, but not very elegantly, because when I click on the icon for some reason a new row is created in the browser below where I clicked (and all content...

Javascript/CSS token field. Much like Cocoa's one.

Hi all! I've made a desktop application which uses Cocoa's NSTokenField: More info about it here: http://developer.apple.com/documentation/Cocoa/Conceptual/TokenField%5FGuide/Introduction/Introduction.html Now I'm remaking this application as webapplication using PHP and AJAX. Is there a way to use a token field (comma seper...

Edit link on div mouseover

On facebook for example - when you put your mouseover a news item, a remove button appears. How can I go about making this happen? Thanks, Elliot ...

JQuery, hide not working in Firefox

Hello, I am currently working on building a very simple site for an open source research project for my University. I am using JQuery to animate the sub-navigation of the site. However, my code only seems to work in IE and not Firefox or Chrome. I'm not sure if it is a compatibility issue, or if it is my fault. I looked up examples on ...

Is it possible to use variables as dom elements?

I have a several input fields in a form each having a unique name. For example, to change the color I would do: testForm.username.style.background = "yellow"; username being the name of the input and testform being the form name I want to do this: replace username with a variable elem so that when I call the function to change the ba...

What's the best way to embed constant server-side tags inside javascript code?

I have a bunch of javascript functions which depend on some server-side constants (such as strings from my resources file). While I was developing them I kept the javascript code in the view header, so I could simply used server-side tags inside my javascript code, but now I'd like to move the javascript functions to a separate file. I...

Translating jquery idiom to YUI

How can I translate the following jquery idiom to YUI? $("a").click(function(event){ alert("Saw a click!"); }); The above is supposed to add a custom on-click event to all anchor tags in the document. ...

HTML forms, add data from another domain

Hi I have missed the cross domain waggon, and have just started investigating. My question is: Is it possible add data to the eg. input/@name="x" field in domain-a.com/form.html from domain-b/add.html? As far as I know it is not possible with JavaScript to write to the domain-a's document from a function in domain-b. But I think I h...

Running JS minification as a maven goal?

I'm trying to use YUI compressor in a maven goal, but I'm pretty new to the inner workings of maven. I see that I can copy all js to a new directory with the following: <copy todir="blah"> <fileset> <!-- A bunch of file extension types --> </fileset> </copy> Now, for each css and js file, I want to run the run the yui compres...

Get all <a> elements in a page using javascript

Is there anyway I can get all of the <a> in a page, I want to apply a new targets to all of them. ...

Get top of current window position relative to the document body

Hello on and all. I am developing a model box jQuery plugin, and I need to know how to get some window properties. The box and its shader div fade over top of the page, and the shader div covers the complete body, not just the window (Important for pages that have horizontal scroll bars). When the model div fades in, it centers itself ...

javascript date subtraction

Hello I am looking for a way to do proper subtraction between two javascript Date objects and get the day delta. This is my approach but it fails for todays date as an input: <script type="text/javascript"> function getDayDelta(incomingYear,incomingMonth,incomingDay){ var incomingDate = new Date(incomingYear,incomingMonth,incomingDay);...

How to access variables from class using static methods?

//my class function myClass() { this.pubVar = 'hello public'; var priVar = 'hello private'; } myClass.staticMethod = function() { //how do i access thos variables here } I tried alert(this.pubVar) and alert(priVar) with no success. What am I doing wrong? I'm going to change the question a bit.. I didn't explain it well t...

Most efficient way to create a zero filled JavaScript array?

What is the most efficient way to create an arbitrary length zero filled array in JavaScript? ...