Tag: programming

Associative Arrays

If you’ve used javascript much, you are probably familiar with arrays. Typically arrays are used to manage lists of items. I frequently use arrays for maintaining information about the state of pages and quiz questions in learning modules, storing a series of properties for each item.

But, there is a problem. To find the particular item you want to use, you must loop through the whole array. Sometimes you can get yourself into a situation requiring multiple loops to get one item of information and performance will suffer.

I recently got to wondering if there weren’t a way to jump straight to the desired item, if the ID of the item were known. Yes there is!

Enter “associative arrays“. Associative arrays allow you to index items by any string key, not just the usual arbitrary index numbers. So you can go straight to the exact item by name without testing for property matches while looping through the array.

Continue reading

Timing Issues and Javascript

Sometimes, when you use javascript to make a change to some element on a page, you will get a Javascript error along the lines of: “element ‘n’ has no properties.” You check your page, and yes, the element is definitely there, and it is definitely named correctly, and your syntax is definitely correct. So where is the problem?

Well, it may be a timing issue. If your script executes before the element targeted by the script has been rendered, it will not find the element. This can particularly be a problem with frames or iframes. The solution is to move the function call to the bottom of the page, after the element has loaded.

Continue reading

How to analyze Captivate Movie structure

If you want to create widgets that control Captivate files with new functions, other than the standard playbar functions, you will need to develop them in flash. Here’s how to figure out what is going on in a Captivate movie file:

Create a Captivate movie, and publish it (Captivate 2) or export it to Flash (Captivate 3). To create my faster-slower widgets, I had to decompile it into an .fla (I used SWFdecompiler )

Open it in Flash, and start exploring the structure. If you are using version 3, by far the best tool you can use include the “debug movie” command.

Continue reading

Detect browser support for style properties

It is common to use object detection to discriminate between browser capabilities (See Quirksmode: Object Detection.

However, sometimes it is necessary to detect whether or not a browser understands a particular CSS style property, and it is not obvious how to do this.

You can’t test for the existence of the property directly but you can test for the data type of the value of the property. If the data type is anything but “undefined”, the property is understood by the browser.

The example below shows a couple of rows from an automatically generated table of items. Each row has a corresponding editable version which shows up when the “edit” button is clicked. The original, non-editable row is hidden at the same time the editable row is displayed. If “display=’block” is used to display the TR, Safari will render it as a TD. To correct this, “display=’table-row” must be used on browsers that understand it.

Continue reading

Javascript validation as a condition for a second function in the same event handler

We use Questionmark quizzing software at my job to create quizzes and tutorials. One of several issues we have had with it has been a login page which did not validate for the kind of ID number we wanted to use. In fact it did not validate at all! We were told that either it couldn’t be done because it would not work with the software (the login page submits some .asp variables), or it would cost us to have it done by their programmers – so we set about trying to make it happen.

The problem was that it uses the onSubmit event to trigger some fancy new window actions. I wanted the validation to take place and stop the new window action as well as the “submitting” action itself. So my first thought was to put a standard validation script on an onBlur event. In other words when people moved the cursor from the validated field to the next field, the validation would occur.

Continue reading