Ajax example: Two Dependent Listboxes & Autofill

Description

This example demonstrates how to implement dependent drop-down menus (dependent listboxes) using Ajax. Additionally, product information is automatically displayed based on the 2nd listbox selection.

Usage

  1. Select a category. The product listbox populates automatically without the page being refreshed.
  2. Select a product. Product information is displayed without the page being refreshed.

Steps to recreate

  1. Add a record form using the Forms tab in the Toolbox panel. In the "Add Record Form" dialog set the following properties:
  2. While in the Design mode, modify listbox properties as follows:
  3. Add another record form (store_products ) to your page using the Forms tab in the Toolbox panel. In the "Add Record Form" dialog:
  4. Rename Label1 to price and Label2 to description.
  5. Use the Insert Row option to insert a row between the price and description rows.
  6. Add Image control the new row using the image option available in the Forms Tab of the Toolbox, then name it image_url
  7. Switch to the HTML mode and add the span tags after the product_name, price and product_description labels as shown in the example:
    <span id="store_productsproduct_name"></span>
    <span id="store_productsprice"></span>
    <span id="store_productsdescription"></span>
    
  8. Run the Feature Builder to create Dependent Listboxes:
  9. Run the Feature Builder again, this time to create AutoFill feature:
  10. Open the features property dialog for  the s_product_id control and add the Ajax Condition feature to determine whether a product is selected in the s_product_id listbox.
    Condition: equals(=)
    Name: store_productsSearchs_product_id
    Source Type: Control
    Name: ""
    Source Type: Expression
    Start event:
    store_productsSearch.onload;store_productsSearchs_product_id.onchange;store_productsSearchs_product_idPTDependentListBox_s_product_id.onsuccess;
  11. In the same s_product_id features dialog add Ajax Hide-Show feature to be used to hide store_products form when the above Condition is false (no product is selected in the s_product_id listbox) and show the form only when the Condition is true (there is some product selected in the s_product_id listbox).
  12. Make cosmetic changes as needed by modifying the text and captions within the HTML.

Database Tables used:

Database: Internet

Tables: store_categories, store_products