javascript

Convert JavaScript String to be all lower case?

How can I convert a JavaScript string value to be in all lower case letters? Example: "Your Name" to "your name". ...

How can I have two different drop down menus depend on the same parent menu?

I have two drop down menus that I want populated with identical data depending on what is selected on the parent drop down menu. Right now, I am using a javascript library that populates one child drop down menu based on a parent, but I need to have two drop down menus populated simultaneously. This javascript library contains a functio...

Trigger button click with JavaScript on Enter key in Text Box

I have one text input and one button (see below). How can I use JavaScript to trigger the button's click event when the Enter key is pressed inside the text box? There is already a different submit button on my current page, so I can't simply make the button a submit button. And, I only want the enter key to click this specific button i...

Cross browser "jump to"/"scroll" textarea

I have a textarea with many lines of input, and a JavaScript event fires that necessitates I scroll the textarea to line 345. scrollTop sort of does what I want, except as far as I can tell it's pixel level, and I want something that operates on a line level. What also complicates things is that, afaik once again, it's not possible to m...

XMLHttpRequest POST multipart/form-data

I want to use XMLHttpRequest in JavaScript to POST a form that includes a file type input element so that I can avoid page refresh and get useful XML back. I can submit the form without page refresh, using JavaScript to set the target attribute on the form to an iframe for MSIE or an object for Mozilla, but this has two problems. The mi...

How do I resequence dropdown list controls like the NetFlix queue from the client side (Javascript)

We have a series of drop down controls that determine the sort order of columns. The problem we are having is when the user selects a column as the 2nd column the other dropdown lists need to have their values changed so that there is only one "2nd". Column A [1] Column B [2] Column C [3] Column D [4] Column E ...

Why does IE give unexpected errors when setting innerHTML

I tried to set innerHTML on an element in firefox and it worked fine, tried it in IE and got unexpected errors with no obvious reason why. For example if you try and set the innerHTML of a table to " hi from stu " it will fail, because the table must be followed by a sequence. ...

How can I escape a DOM name in javascript?

I have a form element that I want to address via javascript, but it doesn't like the syntax. <form name="mycache"> <input type="hidden" name="cache[m][2]"> I want to be able to say: document.mycache.cache[m][2] but obviously I need to indicate that cache[m][2] is the whole name, and not an array reference to cache. Can it be don...

How do I have YAHOO.util.KeyListener disabled when an input element is focused?

I have a MenuBar setup with YUI's MenuBar widget, and I have a YAHOO.util.KeyListener attached to 'document' to get quick keyboard access to the menus and submenu items (e.g. 's' to open the Setup menu). The problem is that the keylistener will still fire when a user is in an input element. For example, a user might be typing 'soup' in...

Is it reasonable to assume my visitors have javascript enabled?

I understand that server-side validation is an absolute must to prevent malicious users (or simply users who choose to disable javascript) from bypassing client-side validation. But that's mainly to protect your application, not to provide value for those who are running browsers with javascript disabled. Is it reasonable to assume vis...

Circle coordinates to array in Javascript

What's the best way to add the coordinates of a circle to an array in JavaScript? So far I've only been able to do a half circle, but I need a formula that returns the whole circle to two different arrays: xValues and yValues. (I'm trying to get the coordinates so I can animate an object along a path.) Here's what I have so far: circle...

Ambiguous JavaScript error [nsSessionStore.js]

I'm seeing an ambiguous error in Firebug. I don't think it's particularly related to the script I'm writing, however I don't have enough details to be able to determine that from this one error alone. Has anyone seen something similar and have a suggestion? error: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERR...

Detecting Unsaved Changes using JavaScript

I have a requirement to implement an "Unsaved Changes" prompt in an ASP .Net application. If a user modifies controls on a web form, and attempts to navigate away before saving, a prompt should appear warning them that they have unsaved changes, and give them the option to cancel and stay on the current page. The prompt should not disp...

Checking for and not printing javascript in generated data?

In my php web app, suppose I want to go the extra mile and in addition to going gangbusters and being anal-retentive about sanitizing my inputs, I also want to ensure that no javascript is being output in strings I am inserting into templated html. Is there a standard way to make sure I don't put javascript in the generated html conten...

Update viewstate after populating a list with ASP.NET AJAX

I've got a dropdown list that is being populated via a webservice using ASP>NET AJAX. On the success callback of the method in javascript, I'm populating the dropdown via a loop: function populateDropDown(dropdownId, list, enable, showCount) { var dropdown = $get(dropdownId); dropdown.options.length = 1; for (var i = 0; ...

Is there a way to retrieve only a portion of a matched string using regex in Javascript?

Say I've got a string, "foo (123) bar", and I want to retrieve all numbers surrounded by the delimiters "(" and ")". If I use varname.match(/\([0-9]+\)/), my delimeters are included in the response, and I get "(123)" when what I really want is "123". Is there a way I can retrieve only a portion of the matched string without following it ...

How to start automatic download of a file in IE?

How do I initialize an automatic download of a file in IE? For example in the download page, I want the download link to appear and a message: "If you download doesn't start automatically .... etc". The download should begin shortly after the page loads. In FireFox this is easy just need to include a meta tag in the header < meta http...

Which web browsers natively support Array.forEach()

Which browsers other than Firefox support Array.forEach()? Mozilla say it's an extension to the standard and I realise it's trivial to add to the array prototype, I'm just wondering what other browsers support it? ...

Dynamicaly populating a combobox with values from a Map based on what's selected in another combobox

Ok, here's one for the Java/JavaScript gurus: In my app, one of the controllers passes a TreeMap to it's JSP. This map has car manufacturer's names as keys and Lists of Car objects as values. These Car objects are simple beans containing the car's name, id, year of production etc. So, the map looks something like this (this is just an e...

What's the best way to loop through a set of elements in JavaScript?

In the past and with most my current projects I tend to use a for loop like this: var elements = document.getElementsByTagName('div'); for (var i=0; i<elements.length; i++) { doSomething(elements[i]); } I've heard that using a "reverse while" loop is quicker but I have no real way to confirm this: var elements = document.getEleme...