Translator
Categories
Archives

How to Use CSS to Style HTML Input Elements Separately

A few day ago, I was doing some CSS styling and ran across something that I thought would be useful.

If you ever want to style multiple HTML input elements separately using CSS, you just need to access the type attribute.

For Example, if I want to set the text color of my text field to white, but I want the text color of my submit button to be black, I would use the following code:

input[type="text"] { color: #FFFFFF; }
input[type="button"] { color: #000000; }

It’s really that simple!

P.S… sorry for the long delay between posts… my wife and I have our second kid on the way so things have gotten very crazy for us!

JavaScript Image Rotator

I created this JavaScript image rotator to solve a problem a client of mine was having on their site last week.

The first step is to create an empty div that the images can be loaded into. The easiest way to access a specific div from JavaScript is to make sure the div has an id, and access the div by referencing the div id as such:

var bannerHolder = document.getElementById('bannerHolder');

Once you have created the div and have a way to reference it via JavaScript, you will need to create an array of image urls to loop through.

var bannerArray = new Array();
var currentImage = 0;
bannerArray = ['http://www.noobflash.com/wp-content/themes/LemonPress/images/JavaScriptImageRotator/google.jpg','http://www.noobflash.com/wp-content/themes/LemonPress/images/JavaScriptImageRotator/yahoo.jpg','http://www.noobflash.com/wp-content/themes/LemonPress/images/JavaScriptImageRotator/msn.jpg'];

Tie these pieces of code together using setInterval to create the timed rotation and you have your image rotator. Get the complete code using the link below:

Get Complete Code

Basic JavaScript Array Tutorial

If you have ever created an array in ActionScript or any other ECMAScript based programming language, creating an Array in JavaScript will be very familiar to you. On the other hand, if you are an array noob, you are certainly not alone. Arrays are a sticking point for many new programmers, but alas, salvation is neigh! Allow me to walk you through the creation of a simple JavaScript array, that, for the most part, can also be used in ActionScript.

What is an Array?
An array, at its simplest, is really nothing more than a collection of items that is assigned as a variable. When an item is added to the array, it is given a number called an index. The item can then be referenced later by calling the array variable along with the index number of the item you want to access. Clear as mud? Great! Let’s see an example.

How do I Create an Array?
My wife is making tacos tonight, so I will use my hunger as inspiration.

Awesome, we just created a delicious array!

  1. The first step in creating an array is to declare a variable for it. In this case the variable I want to use is ingredients.
  2. The second step is to cast the variable as an Array object. Some people would argue that this step isn’t necessary, and they’re correct, but it is a best practice to type cast your variables as often as possible.
  3. The third step is to add items to your array. The easiest way to do that is to set your array variable (in this case ingredients) equal to a bracket enclosed, comma delineated list of items. In my case I added three strings to the ingredients array.
  4. The final step isn’t really needed, but is allows you to see what your array looks like at this point. You will see all three comma delineated strings, Beans, Meat, and Cheese in the alert box. This is normal and just means that the array contains all three of those items.

Now, say you’re a meatetarian… How do you only select the one item of the array that you want? It’s actually as easy as grabbing the meat spoon!… so to speak. You just need to call the name of the array variable with the index of the item you want added in brackets (E.g: ingredients[1]).

There is one important thing you should know about indexes in ECMAScript based languages: counting always starts at 0… I don’t know why the rule exists, I just follow it. The first item in your array will always be index 0 (ingredients[0] = Beans in this case), followed by 1, 2, 3 and so on.

This should be enough to help you get started working with Arrays. Check back soon for more on Arrays including some Intermediate and Advanced Array techniques.

JavaScript Find and Replace

Follow the example below to perform a find and replace in JavaScript.

<script type="text/javascript">
var myString = "I like coding";
myString = myString.replace('coding','sleeping');
document.write(myString);
</script>

Flash Player Version Penetration Update

Adobe Flash Player Penetration by Version as of December 2008
  v7 v8 v9 v10
Mature Markets 99.1% 99.0% 98.6% 55.9%
US/Canada 99.1% 99.1% 98.9% 54.5%
Europe 99.1% 98.9% 98.2% 56.5%
Japan 99.0% 98.8% 98.3% 59.3%
Emerging Markets 98.7% 98.6% 98.1% 55.9%

Source: Adobe.com