Search code examples
javascriptxmlajaxflashforms

Form with xml or excel data dropdowns?


I want to create a form (flash or java/ajax) that allows selection data to be pulled from an xml file.

Example:

A ring builder application - the user selects the ring setting in one dropdown and then they select a diamond in another drop down. But the prices of the diamonds changes every day based upon the market, so we would need to easily update that data - hence an xml or excel file.

It would be even better if the data could be linked - such as selecting a princess cut diamond, then the settings that are only compatible with princess cut show up, and then after selecting a setting, only diamonds that are the right size for the setting show.

Thoughts?

thanks!


Solution

  • I think JSON is more appropriate for such a task. Assuming that your data is stored in a database ( rather than XML or Excel file ) , you could use PHP , or any server side language for that matters to return a set of objects, encode them as a JSON string and pass this info to Flash or JS. Decoding the JSON string in Flash ( or Javascript ) will return the set of objects, to be managed on the client side.

    These objects would basically be your data sets that your menu can then query.

    Practically when the user starts your application, you would only need one server call to get all the necessary data which can then be your data sets for that particular session. Your database can of course be updated as often as you need.

    As for the general structure of your data Objects, try and keep your data separated by concerns, I would suggest to avoid tying things together so as to keep your application flexible. You may not come up with the best structure right from the start so were you to make changes in your menu layout, for instance , you could still reuse the majority of your code.

    //A basic example of DataObject that could store the values retrieved from the XML
    public class DataObject
    {
        public var gemTypes:Array = ["Diamond" , "Ruby" , etc...]
        public var cutTypes:Array = ['Princess' , 'Emerald', etc...]
    }
    
    //A couple of classes you could use to structure your menu
    public class AbstractGem
    {
       protected var _cutType:String;
       protected var _settings:Object;
       protected var _sizes:Array;
    
    }
    public class Diamond extends AbstractGem
    {
    }
    
    public class Main
    {
       public function Main()
       {
          //if a menu calls the princess cut diamond, you can use the properties
          //set from the XML to determine what submenus will be called
          var princess:AbstractGem = new Diamond();
          princess.sizes = [1.5 , 1.8 , 2.0 , ......, 8.0];
          princess.cutType = "Princess"
       }
    }