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

How to cope with being single during the holidays

The buildup to the holiday season begins early, that’s for sure. And if you’re used to being part of a pair strolling arm-in-arm through a winter wonderland, facing this time of year as a single person can really throw a wrench in your ho-ho-ho. The days ahead may seem anything but merry and bright.

“Holidays are hard because most of us have been conditioned to think that the season belongs to families and friends,” explains Bishop Noel Jones, pastor of the 20,000-member City of Refuge faith community in Gardena, CA. “The key to the torment of holiday blues is the conditioning based on our cultural upbringing. This has forged our minds into believing that we need someone with us to make the holiday joyful.” Jones, who's also the author of God’s Gonna Make You Laugh, continues: “This is endemic to our culture. It doesn’t matter whether you’re newly or ‘terminally’ single, the problem is being conditioned to believe it takes two to make holidays joyous.”

If you’re ready to begin reconditioning yourself for the single holiday season ahead, read on...

Adjust your attitude
Hard as it may be to imagine life after a breakup, there is one... assuming you choose it. Mark Rogers, a Dallas-based counselor and relationship coach, says it’s crucial to have a life. “Life’s supposed to be juicy and joyful,” he counsels. “So embrace your personhood, not your partnership status. If you don’t like your life, if your passions are all pastel, if your color’s washed out, your adventures listless, your hobbies hobbled, and your courage for new activities and novel interactions has dried up and blown away, then you may be hoping a romance will start blood flowing inside a turnip,” he says. (It won’t.)

“It’s not singlehood that’s a liability, it’s stagnation,” adds Rogers. “Get the juices flowing in your life, and then your relationship status becomes an attribute, not an identity.”

Think about it: the fun, interesting people you want to date want to date someone fun and interesting, too. “Get serious about being emotionally mature and interactionally interesting,” Rogers concludes. “Offer potential partners light-heartedness, passionate engagement with life, and a willingness to learn the dance steps of intimacy. That combination is practically irresistible.”

Use your network
“If you’re suddenly solo, you probably envision a holiday season spent sitting at home, watching It’s A Wonderful Life for the 45th time (this year),” laughs Jeanne Hurlbert, professor of Sociology at Louisiana State University. “But it doesn’t have to be that way. Focus on what you have — friends, family, colleagues — rather than what you lack. Enjoy those relationships fully. Choose to spend time with people who are fun and who will embrace your single status — not pity it — and will help you embrace it, too. Rekindle relationships with special people with whom you’ve lost touch. Renewing contact with old friends may provide a special holiday gift for both of you.”

Hurlbert also suggests hosting your own seasonal party to signal to yourself and your friends that you’re ready for a festive holiday. “Chances are, you’ll stimulate lots of invitations and activity,” she says. “And that will provide opportunities to expand your network.”

There are other ways to expand your social circle and fill that hole in your schedule. Join a new organization, or volunteer your time at a shelter or food bank. “Lots of organizations are looking for helping hands this time of year,” Hurlbert notes. “Providing that help will not only lift your mood, it will also introduce you to new people.”

Take care of yourself
While being a singleton can be a bummer, it does provide you with an opportunity to invest in your own well-being. “Taking time to unwind can decrease your stress levels and improve your health and relationships,” notes Mental Health America President and CEO David Shern. “Try meditating, exercising, engaging in a hobby or talking with a friend. It’s your time, so spend it doing something you enjoy.”

This is important because mental health is integral to our overall health and wellness. “Negative psychological factors, such as stress and depression, can have serious effects on physical health,” he explains. “Stress, for instance, is closely linked to high blood pressure, heart disease and obesity. Learning habits that promote mental health therefore helps us protect and strengthen our overall health and well-being.”

And if you feel good, you’ll look good. That will help your attitude stay positive — and make you more attractive to potential suitors.

No one’s saying it’s easy being suddenly single during the holidays. Nor are we saying it’s easy to change your attitudes and conditioning. But it is possible, with a little effort. And starting now, before the holiday crush is upon you, will make it easier. Who knows? If you develop a happy and healthy attitude about the holidays, you might just find love under the mistletoe!

Full Story