Monday, November 29, 2010

Form field show/hide via JS

I'm working on an online credit app for a client and need to be able to add additional fields from a selected radio button.

Ex: There is a radio group that has two options, one is "Business" one is "Individual"
If someone clicks on Business, a text field for DBA needs to appear, If Individual is selected, DBA needs to be hidden.

Solution:

You need to set a onclick for each input radio to show or hide the additional input text.

Like:

input type="radio" name="type" value="Business" onclick="document.getElementById('dba').style.display='block';"

input type="radio" name="type" value="Individual" onclick="document.getElementById('dba').style.display='none';"

input type="text" name="dba" id="dba" value=""

Building Drag-and-Drop DIVs: Developing a Basic Script

# Building `Drag-and-Drop` DIVs: Developing a Basic Script
# Setting up the basics: emulating drag-and-drop triggers
# Dragging DIV elements: defining the “startDrag()” function
# Moving DIVs around the web document: defining the “dragDiv()” function
# Gluing the pieces together: defining the complete DIV dragging script

Full Tutorial

Sorting Elements by ID in javascript

So I have, say, a list of members that are sorted out on the page in sections, each section has its own id#. By default I want to display all of the IDs, but when someone selects a radio button I want only one section (id) to be shown.

Solution 1

First,

dom element id's can not be numbers (some frameworks will no work properly because of this)

that aside,

You want a list of all the id's in a javascript array, populate it however you want ..

var ids = new Array('id1','id2','id3','id4');
var current = 'id1'; // Currently shown member id

function switch($id) {
hide = new Array();
len = ids.length;
for(x=0; x< ele =" document.getElementById($id);" display =" '';" len =" arguments.length;" x="0;" ele="document.getElementById(arguments[x]);" display="none" in="" your="" radio="" buttons="">

input onclick="switch(this.value)" value="" type="radio"

Solution 2

If you know the ID of each section, and depending on the structure of your HTML tags, you can can loop through all the main tags within a section ( by #id ) and hide all except for the one that referred to by the radio butotn.

input onclick="single( 'item3', 'section1' )" value="" type="radio"

function single( id, sec )
{
var section = document.getElementById( sec );
var items = section.getElementsByTagName( 'li' );

for( var i=0; i < items.length ; i++ ) { items[i].style.display = ( items[i].id === id ) ? '' : 'none'; } }

Move the object using the Action Script and cursor.

Step 13

Then, select again the cursor, open the Action Script Panel (F9), and paste this script:

onClipEvent (load) {
}
onClipEvent (mouseMove) {
xm = getProperty (_root, _xmouse );
ym = getProperty (_root, _ymouse );
setProperty("_root.cursor", _x, xm);
setProperty("_root.cursor", _y, ym);
}

onClipEvent (mouseDown) {
with (_root.cursor) {
gotoAndStop("clench");
}
}

onClipEvent (mouseUp) {
with (_root.cursor) {
gotoAndStop("open");
}
}

We're done!

Full Tutorial

Move the Object using the arrow keys

Create a new layer and name it Action. Select it, click on the first frame, press F9 or select Window > Actions to open the Actions panel.

After that, enter the following ActionScript code inside the Actions panel:

information_txt.text = "Use your arrow keys to move the balloon!";
var speed:Number = 4;
object_mc.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
this._x = this._x+speed;
} else if (Key.isDown(Key.LEFT)) {
this._x = this._x-speed;
}
if (Key.isDown(Key.UP)) {
this._y = this._y-speed;
} else if (Key.isDown(Key.DOWN)) {
this._y = this._y+speed;
}
};

Action Script explanation:

1.information_txt.text = "Use your arrow keys to move the balloon!";
1. Display instructions on the screen

2 .var speed:Number = 4;
2. Set the speed for the object

3. object_mc.onEnterFrame = function() {
3. Capture the onEnterFrame event of the object_mc movie clip

4. if (Key.isDown(Key.RIGHT)) {
this._x = this._x + speed;
} else if (Key.isDown(Key.LEFT)) {
this._x = this._x - speed;
}

4. Move horizontally if the RIGHT or LEFT arrow keys are pressed

5. if (Key.isDown(Key.UP)) {
this._y = this._y - speed;
} else if (Key.isDown(Key.DOWN)) {
this._y = this._y + speed;
}
};

5. Move vertically if the UP or DOWN arrow keys are pressed

We're done!

Test your Movie (Ctrl+Enter).

Full Tutorial

Friday, November 26, 2010

Suggested Directory Organization

The FlexUnit 4 framework doesn’t prescribe a directory structure for testing files; however, the following suggestions work well:

  • Each test suite should have its own directory.
  • The suite definition should reside in this directory.
  • Within the directory for the test suite, create a tests directory.
  • Inside of this directory store each of your test cases for this test suite.
  • Any additional classes needed to accomplish testing can be stored in further subdirectories.

Ideally, the directory structure looks something like this

src/
testSuite1/
TestSuite1.as
tests/
TestCase1.as
TestCase2.as
TestCase3.as
testSuite2/
TestSuite2.as
tests/
TestCase1.as
TestCase2.as
TestCase3.as


Full Documentation

Thursday, November 25, 2010

5 Holiday Shopping Mistakes to Avoid

With the holiday season now in full swing, it's easy to get caught up in the hype and fall for a few expensive shopping mistakes. Sure, we all want to give our loved ones a holiday to remember, but there's no need to deck the halls with boughs of money to have a happy holiday.

[In Pictures: 12 Money Mistakes Almost Everyone Makes]

To help you stay off Santa's naughty list, here are five holiday shopping mistakes you make, and the fixes that can save you money.

Mistake 1: You don't have a gift list. If making a list and checking it twice is good enough for Santa, then stop being a Scrooge by skipping this important financial planning step. Running around the mall not knowing what to buy is a surefire path to blowing your budget--especially when you're pressed for time.

The Fix: Budget today for tomorrow's gifts by downloading this free Gift Giving Worksheet. As you think of gift ideas, just add them to the list with your expected budget.

Mistake 2: You don't track holiday spending. You spent how much on decorations, wrapping paper, and stocking stuffers? Ouch! Those little holiday spends can add up to a lot if you're not careful. Not tracking all those little splurges and expenses can leave you with a huge bill to pay in January. Not fun.

The Fix: Stay on the right financial track by using this free Holiday Expense Tracking Spreadsheet. There are a myriad of costs to keep in mind during the holidays, and it's easier to stay on budget when your spending list is up-to-date.

Mistake 3: You don't look for a discount. Paying full price for anything when a better deal can be found can turn any Santa into a Scrooge. Bah, Humbug! Many last minute shoppers are too desperate to find a deal when the big deadline looms.

The Fix: Avoid paying the price for not shopping around--go online and comparison shop before spending your hard-earned cash. Many retailers offer online promotional codes and coupons to savvy shoppers, so finding that deal is just a click away. Check out How to Find Big Savings with Secret Online Coupons for the best ways to save like Santa.

[Visit the U.S. News My Money blog for the best money advice from around the web.]

Mistake 4: You don't give homemade gifts. Buying packaged gift boxes, baskets, and other store-wrapped goodies is tempting, but expensive. Pre-made gift packages are sold for top dollar, and it's easy to make something special for far less. Besides, making something from scratch is thoughtful and can also save you money.

The Fix: You don't need to be a crafty or have a special skill to give a homemade gift this year. These 8 Homemade Gifts in a Jar are super simple--just layer tasty ingredients into a mason jar and add a gift tag. Need a hostess gift? Try baking a batch of tiny tarts (see How to Make Pie in a Jar) or make your own gift basket by adding a cookbook to a few recipe ingredients.

Mistake 5: You don't shop at home first. Filling your shopping cart with holiday decorations, gifts, and food supplies is a massive money mistake if you already have the goods at home. Buying stuff you already own adds clutter and costs money that could have been used to pay off your credit card or pay down your student loan.

The Fix: Take a peek in your pantry, open your closets, and search the basement before heading to the store. It's possible to deck out your home with everyday items to get that holiday feel. Check out 5 Ways to Decorate Your Holiday Table on a Budget for some stunning ideas.


Full Story