A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: How to validate combo boxes?

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    How to validate combo boxes?

    Please help me out with this problem. Everything else has been working perfectly except when it comes to validating combo boxes.

    This is part of the code:

    if (meet_first.text == "" || meet_last.text == "" || meet_email.text == "" || meet_thetime.text == "" || meet_month.getselectedItem() == "" || meet_day.getselectedItem(0) == "" || meet_ampm.getselectedItem() == "" || meet_reason.text == "")

    {
    result_meet.gotoAndPlay("go");
    result_meet.myresult.text = "Fields with (*) must be filled.";

    }

    Am I using the correct properties?

    Any help would be very appreciated.
    * mussicc

  2. #2
    That web bloke Stoke Laurie's Avatar
    Join Date
    Jan 2006
    Location
    England
    Posts
    869
    Quote Originally Posted by mussicc
    result_meet.gotoAndPlay("go");
    result_meet.myresult.text = "Fields with (*) must be filled.";
    mussicc
    It looks like you have taken this from a Chris Seahorn load vars example, which is fine, as long as you realise that the gotoandplay function refers to a movie clip chris had on his stage called myresult I think. otherwise the code looks fine.

  3. #3
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    Quote Originally Posted by mussicc
    Please help me out with this problem. Everything else has been working perfectly except when it comes to validating combo boxes.

    This is part of the code:

    if (meet_first.text == "" || meet_last.text == "" || meet_email.text == "" || meet_thetime.text == "" || meet_month.getselectedItem() == "" || meet_day.getselectedItem(0) == "" || meet_ampm.getselectedItem() == "" || meet_reason.text == "")

    {
    result_meet.gotoAndPlay("go");
    result_meet.myresult.text = "Fields with (*) must be filled.";

    }

    Am I using the correct properties?

    Any help would be very appreciated.
    * mussicc
    Could you attach your fun file? I see where you're probably getting confused but I can't help if I can't see where your textboxes or variables lead.

    Just to note though, you're trying to validate text boxes in your example not comboboxes.

    Make sure to include dependencies with your fun file. I can help then.
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    This example is a little more involved than you need but it's meant to give you ideas. Dissect what is useful and save the rest for down the road

    http://flex.hobby-site.com/examples/...ovalidate.html
    Attached Files Attached Files

  5. #5
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    FUN file attached

    Yes, indeed, I'm using Chris Seahorn's loadvars script. I have removed the text boxes to make it more simple and less confusing.

    Your help is great appreciated!
    * mussicc
    Attached Files Attached Files

  6. #6
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Thanks!

    Thanks, Chris - That's exacltly what I was looking for!

    *mussicc

  7. #7
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Before I head back to the cave...I want to mention... (Wilbert has also mentioned this many times before as well)......


    Always make sure to give the components at least two frames...the first one to create it and the scripting on the second (or any frame after the original frame it was placed in the timeline).

    For example if I coded that whole thing on one frame I could validate the combobox (read it's chosen value) but could not send commands to it. This line which tells it to default to it's first item (which has no value on purpose ):

    meet_ampm.setSelected(0);


    would fail on a one frame movie using a combo.

    As long as the combo is already placed and I script it on a following frame (frame two in my example) it will accept the command to control it as well as read it

  8. #8
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    That is a lot to do for reading the choice of a simple checkbox. Here is what I do. You choose with method works best for your application.

    On stage are two items.

    my combobox and a dynamic textbox.

    Name your textbox "choice1" or whatever you want.

    Select properties of the combobox. Add your values. In the on Change box add this action script.

    Code:
    _root.choice1.text = getValue();

    That's it.

    Whatever the user selects will put the response in the textbox and you can now send the data using which ever method you choose.

    When the form goes live you can hide the textbox behind your background image, off stage (_x = 2000; ) or just change the colors other attributes so it can't be seen.

    See it in action
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  9. #9
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    So...let's see now...his original....


    if (meet_first.text == "" || meet_last.text == "" || meet_email.text == "" || meet_thetime.text == "" || meet_month.getselectedItem() == "" || meet_day.getselectedItem(0) == "" || meet_ampm.getselectedItem() == "" || meet_reason.text == "")

    His expected new based on the assumption no dropdown has been clicked (because most likely his does not contain an empty item value but even if it did it's easily addressed)...


    if (meet_first.text == "" || meet_last.text == "" || meet_email.text == "" || meet_thetime.text == "" || meet_month.getselectedItem() == "" || meet_day.getselectedItem(0) == "" || meet_ampm.getValue()==undefined || meet_reason.text == "")


    At the very worst even if he does choose to use a default with no value all he needs is:


    meet_ampm.getValue()==undefined || meet_ampm.getValue()=="" added

    So your solution is to add another textfield to track what is already contained in the value (or lack thereof ) in the combo? That is sound advice or efficient?...OK...if you say so...



    I'm also pretty sure that your concerns here:

    That is a lot to do for reading the choice of a simple checkbox.

    Were pointed out here:

    This example is a little more involved than you need but it's meant to give you ideas. Dissect what is useful and save the rest for down the road
    Thanks for adding an uneeded object to his movie though...that might also be something he wants to do down the road

  10. #10
    Senior Member
    Join Date
    Jul 2001
    Location
    Tinley Park, IL
    Posts
    702
    Sigh....why do you get so pissed when someone offers another point of view? I sense much anger in you.

    In my example the textbox is only there for testing. It can be removed when it goes live.

    Maybe this example would be better explained.
    My Sites: Gaming Site Nightshade Studios MyKM Tutorials

    --------------------------------------------------
    What I'm using: Gimp, Koolmoves, Sepy, HTML-Kit, Inkscape

  11. #11
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Who said I'm pissed? I'm actually in a great mood. Another bad call D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center