I found a sample on this site of a parts form with reactive drop down lists that automatically display a price. I like it's capability and would like to use something a little more sophisticated.
This is the code:
// Master List of Lists // Each entry in this object listeral is the name of an assembly, // The associated value is the item list, where each item is a name value pair, [<Part>,<Price>] var oAssemblyParts = { Chasis: [ ["-","None"], ["Rear Bracket",205.95], ["Front Bracket",185.95], ["Long Support",44.95],["Front Bearing",48.95]], Clutch: [ ["-","None"], ["Plate 1",15.95], ["Plate 2",22.95], ["Inside Shaft",44.95],["Outside Shaft",32.95]], Brake: [ ["-","None"], ["Master Cylindar",139.95], ["Slave Cylindar",85.95], ["Pad",15.95], ["High Presure line",22.95]], Coolant:[ ["-","None"], ["Pump",35.95], ["Thermostat",19.95], ["Coolant Line",8.95],["Reservoir",17.95]] }; //******************************** // All of the functions below are made "Row" generic, i.e. they work no matter // which row the field is on that calls the function. This is done by pre-fixing // each of the field names with the row name. The row name can then be extracted // from the name of the field that calls the function and used to acquire other // fields on the same row. //////////////// // SetPartEntries() // // Function for setting the parts list based on the assmebly selection value // // This function is specifically setup to be called from the Change Event // of the Assembly List. It will not work from another event because the // "event.value" parameter is used // function SetPartEntries() { // Only run this code on when the selection is commited. if(event.willCommit) { // There are 3 rows in the order form so in order to use other fields in // the same row we first have to acquire the name of the row // we are operating on. This is part of the List field's name, so we // just have to split it off var cRowName = event.target.name.split(".").shift(); // Now get the new parts list from the Master List // Since the selection is being committed, event.value contains the selection text var lst = oAssemblyParts[event.value]; // If an entry is selected that we don't have a parts list for, then // the parts list is just cleared. if( (lst != null) && (lst.length > 0) ) this.getField(cRowName + ".PartSelect").setItems(lst); else { this.getField(cRowName + ".PartSelect").clearItems(); } // We have a new parts lists and the first entry is // is a non-selection. so clear the price field. this.getField(cRowName + ".Price").value = 0; } } //////////////// // SetPriceValue() // // Function for setting the price value based on the Parts selection value // // This function is specifically setup to be called from the Change Event // of the Parts List. It will not work from another event because the // "event.willCommit" and "event.changeEx" parameters are used // function SetPriceValue() { // Only run this code on the un-committed change. This fields is set up // for Commit on select so we know the value will be committed if(!event.willCommit) { var cRowName = event.target.name.split(".").shift(); // If the export value is Not a Number then // set the price to zero. var nSelExp = 0; if(!isNaN(event.changeEx)) nSelExp = event.changeEx this.getField(cRowName + ".Price").value = nSelExp; } } //////////////// // DoTotalCalculation() // // Function for calculating the total. While this is a simple calculation // putting it in a document level function instead of each individual total // field means that it only has to be entered once and is updated in only a // single location (i.e., if we have to make modifications) // function DoTotalCalculation() { var cRowName = event.target.name.split(".").shift(); event.value = this.getField(cRowName + ".Price").value * this.getField(cRowName + ".Quantity").value; }
My desire:
I want a single option field that will trigger other pull downs.
example: one field to choose North America or South America or Europe.
Then, I would like a pull down option to activate based on that first option above.
example: if North America was chosen, I'd like to have the option of east, west, and central to be available. if South America, Brazil, Chile, Peru.
(this could probably be simplified by using NA-East, -West, -Central, SA-Brazil, -Peru, -Chile; that's not to important. just only selection step or two.)
Now if NA-East were chosen, I need more than one value added, so NA-East would fill in the appropriate fields of its row with say, 19, NJ, 07054. Once chosen, these values would remain fixed until manually changed by a new option selection of this row.
I would then like to be able to change that first option selection to say, South America and then chose SA-Brazil in the second row and get a similar result in related fields of same row; text, zone, reference.
Also, the script above seem to be looking a some point for numbers only, I'm having text-number combos that I need to keep as text-number combos, so I would need to not worry if the value returned is a number or not.
This is sounding all complicated and problematic to me so I'm really hoping one of you out there understands what I'm getting at and can help.
While I understand the explanation given with the code in how it works, I don't know how to extend the number of values that can be put into more then one field of same row. Also, I don't know how to get this code to just initiate off one common field that is separate from the rows. My head hurts now. I hope yours doesn't. If so, sorry.
Thanks in advance,
Jim.
If all you want is find one specific item (with all its values), you might look at a popup menu approach. You would have a button which will pop up a hierarchical popum menu which returns either the index number of the item in your master table, or directly fills the fields you are interested in. If you return the index number of the item in your master table, you then use that and fill the fields. If you want to fill the fields directly, you return an array with the values to fill.
If you really want a bunch of dynamically loaded drop downs (in other word, combo boxes), your master table might become a bit more complex. Essentially you can set the return value of each combo box element to point to an array which is structured like the setItems() array for a combo box, and then fill the subsequent box accordingly.
At the very end of your chain of combo boxes, you again would point to an array containing the values to fill into your fields.
Hope this can help.
Max Wyss.