This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes exclusive choice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "exclusive choice" Watch "exclusive choice" New topic
Author

exclusive choice

Chris Baron
Ranch Hand

Joined: Mar 21, 2003
Posts: 1049
Hi,
this is for a Browsergame i'am playing in an ally.
We're programming a report tool to keep the ally-mates better informed about ones combats.

Ok, it's about a village where a combat took place:
the village always has one troup of the defender and none, one or two support troups.
The troups are grouped by tribes.

The "reporter" has 3 selectboxes, where he has to pick the tribes of the participants from.
The choices have to be exclusive. If the defender e.g. has Romans, support 1 + 2 must not have them.
If defender=germans and support1=gauls and there is a support2, support2 has to be roman.
The selectboxes will have the following names and keys-value-pairs:
Defender
  • 0=Please Select
  • 1=Romans
  • 2=Germans
  • 3=Gauls

  • Support1
  • 0=Please Select
  • 1=Romans
  • 2=Germans
  • 3=Gauls

  • Support2
  • 0=Please Select
  • 1=Romans
  • 2=Germans
  • 3=Gauls

  • The tool will validate the input with JavaScript, but this doesn't matter here.
    It's rather about the puzzle, how to solve the validation with the shortest, firmest code
    cb
    [ February 19, 2005: Message edited by: Chris Baron ]
    Rachel Swailes
    Ranch Hand

    Joined: May 18, 2004
    Posts: 434
    What about instead of validating after the user's selection - limit the selection that the user can make. For example, if he selects Gauls in defender then remove Gauls from the other selection boxes.
    Chris Baron
    Ranch Hand

    Joined: Mar 21, 2003
    Posts: 1049
    Hi Rachel,
    i had this idea too, but gave it up, because it's very confusing if one wants to change the selections. I have an "onChange" validation with an array at the moment. Simplified:


    It's working fine, but i wonder how to solve this mathematically.
    cb
    [ February 23, 2005: Message edited by: Chris Baron ]
    Eugene Lucash
    Ranch Hand

    Joined: Feb 19, 2005
    Posts: 77
    I wandering, who needs a mathematical model when solution is simple enouph in terms of object manipulation and behaviours?
    Warren Dew
    blacksmith
    Ranch Hand

    Joined: Mar 04, 2004
    Posts: 1332
        
        2
    A variant on Rachel's suggestion: disable the radio buttons rather than making them disappear entirely.

    Or maybe that's what Rachel meant.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: exclusive choice