What's the best and most efficient way to count keywords in JavaScript? Basically, I'd like to take a string and get the top N words or phrases that occur in the string, mainly for the use of suggesting tags. I'm looking more for conceptual hints or links to real-life examples than actual code, but I certainly wouldn't mind if you'd like...
I am working on a form widget for users to enter a time of day into a text input (for a calendar application). Using JavaScript (we are using jQuery FWIW), I want to find the best way to parse the text that the user enters into a JavaScript Date() object so I can easily perform comparisons and other things on it.
I tried the parse() met...
I've created a tool that is used with a fairly popular music retailer.
The tool provides an enhanced search feature (transparent last.fm results, no ads, no lameness, nothing creepy) and I've found the most useful and unobtrusive way to display the search is as a toolbar using the much maligned iframe. This allows users to load search w...
In JavaScript is it wrong to use a try-catch block and ignore the error rather than test many attributes in the block for null?
try{
if(myInfo.person.name == newInfo.person.name
&& myInfo.person.address.street == newInfo.person.address.street
&& myInfo.person.address.zip == newInfo.person.address.zip) {
this.set...
I have a select element in a form, and I want to display something only if the dropdown is not visible. Things I have tried:
Watching for click events, where odd clicks mean the dropdown is visible and even clicks mean the dropdown isn't. Misses other ways the dropdown could disappear (pressing escape, tabbing to another window), and...
Say that I write an article or document about a certain topic, but the content is meant for readers with certain prior knowledge about the topic. To help people who don't have the "required" background information, I would like to add a note to the top of the page with an explanation and possibly a link to some reference material.
Here'...
What aspects of the UpdatePanel are sensitive to time?
I have an UpdatePanel that works fine. If I leave the page for a few minutes and come back, the UpdatePanel doesn't work. Looking at firebug, I see that it sends the Request and gets a Response back. However, the page itself doesn't update. I'm not seeing any script errors eithe...
I've got a page with a normal form with a submit button and some jQuery which binds to the form submit event and overrides it with e.preventDefault() and runs an AJAX command. This works fine when the submit button is clicked but when a link with onclick='document.formName.submit();' is clicked, the event is not caught by the AJAX form s...
Is it possible to highlight text inside of a textarea using javascript? Either changing the background of just a portion of the text area or making a portion of the text selected?
...
I have a site, from which you can download an HTML file. This HTML file contains a form with hidden fields, which is right away posted back to the site using JavaScript. This is a way of allowing users to download to their own machine data that they edit on the site.
On some machines, you get an IE "yellow bar" when trying to open the f...
I was recently tasked to document a large JavaScript application I have been maintaining for some time. So I do have a good knowledge of the system.
But due the sheer size of the application, it will probably take a lot of time even with prior knowledge around the code and the source code itself in uncompressed form.
So I'm looking for...
I am writing a graphics application in Java. Eventually I would like to build in a scripting language so things are programmable. Which language library do you recommend?
Likely suspects are:
Rhino (JavaScript)
JRuby (Ruby)
Jython (Python)
Less likely candidates are:
Whip up my own language using JavaCC
LuaJava (Lua)
Groovy
JavaFX...
I've recently read the Yahoo manifesto Best Practices for Speeding Up Your Web Site. They recommend to put the javascript inclusion at the bottom of the HTML code when we can.
But where exactly and when ?
Should we put it before closing </html> or after ? And above all, when should we still put it in the <head> section ?
...
I'm writing some JavaScript code that needs to fire the click event for a link. In Internet Explorer I can do this
var button = document.getElementById('myButton');
button.click();
But this doesn't work in Firefox, and I assume any other browser. In Firefox, I've done this
var button = document.getElementById('myButton');
window....
According to this article (http://msdn.microsoft.com/en-us/library/cc197951(VS.95).aspx) Silverlight 2 Beta 2 supports the DataContractJsonSerializer object. But, when I try to use it VS says "Type 'DataContractJsonSerializer' is not defined".
I have a method marked as ScriptableMember that gets called from JavaScript and is passed an O...
I am interested to know if there is any way i can check from javascript code if an html element has overflow in it's content (but with the overflow property set to visible - so no scrollbars on the element). Can i check irrespective of scrollbars for overflow content (in a div tag for instance)? Thanks in advance.
...
What is the best way to find if an object is in an array ?
This is the best way I know:
function include(arr, obj) {
for(var i=0; i<arr.length; i++) {
if (arr[i] == obj) return true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
...
I have a sparse array in Jscript, with non-null elements occuring at both negative and positive indices. When I try to use a for in loop, it doesn't traverse the array from the lowest (negative) index to the highest positive index. Instead it returns the array in the order that I added the elements. Enumeration doesn't work either. Is th...
After updating or creating a record I use url helper to redirect to the part on the page where the record happened to be located:
if record.save
....
redirect_to records_url, :anchor => "record_" + record_id.to_s
end
the resulting url will be something like
http://localhost:3000/records#record_343242
I want to highlight the rec...
Are there any commonly used patterns in Javascript for storing the URL's of endpoints that will be requested in an AJAX application?
For example would you create a "Service" class to abstract the URL's away?
...