This tutorial demonstrates how to use Data Bridge 2.0 to implement dynamic drop-downs, where a choice in one select list populates another select list.
Data Bridge 2.0 uses Ajax (Asynchronous JavaScript and XML) to dynamically modify portions of the web page without refreshing. This allows the selection of an item in one list to entirely update a second list. This Data Bridge 2.0 feature is extremely powerful and can be used in many ways, including the replacing the functionality of the Dynamic Dropdowns extension, as shown in this tutorial.
- Dreamweaver CS3 or newer
- Data Bridge 2.0 or higher, installed and activated in Dreamweaver
- PHP site defined in Dreamweaver
- SQL sample files to use with this tutorial: nwbsa.sql
- PHP sample files to use with this tutorial: Dynamic Drop-downs Tutorial.zip
Using the Data Bridge extension, you will learn how to use one select list to dynamically populate a second select list.
Step 1: Create a Dreamweaver PHP site
Your Dreamweaver site should include a local testing server set to use PHP as a server model. After the site is created, follow these steps:
- Open the tutorial files, Dynamic Drop-downs Tutorial.zip.
- Add all files and folders contained in the expanded zip archive to the site root.
Step 2: Set-up MySQL database
Using phpMyAdmin or a similar MySQL management tool, follow these steps:
- Create a new database called nwbsa.
This database has two tables, towns and teams, that you will use in the tutorial.
- Import the file nwbsa.sql, found in the files added to the Dreamweaver site in the source folder.
Your preliminary set-up is now complete.
In this section, you'll insert the needed HTML for the primary page.
Step 1: Add form and form elements
We'll start by adding a basic form to the page and then inserting a form with the required properties.
- Open the file, main.php.
- Place your cursor in the <div id="mainContent"> tag.
- From the Insert menu, Form category, choose Form.
- In the Property inspector, set the Method attribute to POST.
- From the Insert menu, choose Label.
- Within the <label> tag, enter Towns: followed by a space.
- Place your cursor after the closing </label> tag, choose Select from the Insert menu, Form category.
- With the <select> tag highlighted, in the Property inspector Name field, enter towns.
Step 2: Add a div tag for second select list
You'll need to provide an empty <div> to hold the dynamically inserted (and populated) second select list. Make sure to give this div an ID.
- Place your cursor after the closing </form> tag.
- In Code view, enter the following code:
<div id="childSelect"></div>
- Save your page.
Now it's time to integrate the dynamic data from your database. To do this, you'll need to first add a recordset and then dynamically populate your select list.
Step 1: Add database connection
Before we can add a recordset to the page, we'll need to establish a connection to the database.
- Choose Windows > Databases.
- Click Add (+) and select Dynamic MySQLi Connection.
- In the Dynamic MySQLi Connection dialog, insert the following values:
- Connection name: connNWBSA
- Charset: default
- MySQL server: localhost
- User name: [YOUR_DATABASE_USER_NAME]
- Password: [YOUR_DATABASE_PASSWORD]
- Click Select next to the Database field, and from the dialog list, choose nwbsa.
- Click OK.
Step 2: Create rsTowns recordset
Now that the recordset is available to us, we'll use it to dynamically populate the select list.
- From the Server Behaviors panel, click Add (+).
- Choose Recordset.
- In the Recordset dialog, make sure the Simple interface is displayed (click Simple if the Advanced UI is shown), and set the following values:
- Name: rsTowns
- Connection: connNWBSA
- Table: towns
- Columns: All
- Filter: None
- Sort: townName Ascending
- Click OK.
Step 3: Bind dynamic data to list
With our rsTowns recordset defined, we can now bind the dynamic data to the select list.
- Choose the <select id="towns"> list.
- In the Property inspector, click the Dynamic button.
- When the WebAssist MySQLi Dynamic List/Menu dialog opens, first make sure Menu is set to "towns" in form 0.
We'll add a static option that will appear before the dynamic data to help guide the user.
- For Static Options, click Add (+).
- Set Value to None.
- Set Label to First choose a town and press Tab.
- From the Options from recordset list, choose rsTowns.
We'll match the town name in the teams data to the town name selected in this list.
- Set both Values and Labels to townName.
- Click OK.
- Save your page.
In this section, we'll work with the static, HTML elements of the child page. The child page will hold the second select list and, eventually, be integrated into the main page.
Step 1: Add form elements
This secondary page will eventually be integrated into the main page, so here we'll add the HTML for the second select list. You'll notice we don't need to add a new form tag, because the child page is not independent and the body elements will be inserted into the form within the main page.
Because WebAssist refers to child pages used by Framework Builder as plugins, I like to store such pages in a folder with that name.
- Open the file, plugins/childSelect.php.
- Place your cursor in the <body> tag.
- From the Insert menu, Form category, choose Label.
- Within the <label> tag, enter Teams: followed by a space.
- Place your cursor after the closing </label> tag, and choose Select from the Insert menu, Form category.
- In the Propery inspector Name field, enter teams.
- Save your page.
Time to get dynamic on the child page. Here, as with the main page, we'll establish the database connection, create the recordset and then bind it to the select list.
Step 1: Adding the Database Connection
As with the main page, we'll need to establish a connection to the database. Since it's already been created, all we need to do is add it to the page.
- Place your cursor at the top of the page in Code view.
- From the Databases panel, select connNWBSA.
- Right click and choose Insert code.
- Save your page.
Step 2: Define child page recordset
Again, we'll dynamically populate the select list - but for the child page, we'll need to filter our data according to a specific variable, the value of the towns select list POSTed to the page.
- From the Server Behaviors panel, click Add (+).
- Choose Recordset.
- In the Recordset dialog, make sure the Simple interface is displayed, and set the following values:
- Name: rsTeams
- Connection: connNWBSA
- Table: teams
- Columns: All
- Filter: teamTown = Form Variable towns
- Sort: teamName Ascending
- Click OK.
Step 3: Bind dynamic data to child page select list
With our rsTeams recordset defined, we can now bind the dynamic data to the select list on the child page.
- Choose the <select id="teams"> list.
- In the Property inspector, click the Dynamic button.
- When the WebAssist MySQLi Dynamic List/Menu dialog opens, first make sure Menu is set to select "teams".
Again, we'll add a static option that will appear before the dynamic data to help the user.
- For Static Options, click Add (+).
- Set Value to 0.
- Set Label to Then choose a team and press Tab.
- From the Options from recordset list, choose rsTeams.
- Set both Values and Labels to teamName.
- Click OK.
- Save your page.
Step 4: Show static option conditionally.
To keep our user experience clean, we'll use a WebAssist server behavior to only show the static option if the rsTeams recordset is empty -- which will only be the case if a town has not been selected.
- Select the static <option> inserted in the previous step.
- Choose WebAssist > MySQLi > Show Region > Show if Recordset Empty.
- In the WebAssist MySQLi Show if Recordset Empty dialog, make sure rsTeams is selected and click OK.
- Save your page.
There appears to be an issue where sometimes Dreamweaver will not place the closing PHP code in the proper position. Make sure that the following code is placed directly after the closing </option> tag:
<?php } // Show if mysqli recordset empty ?>
In the final two steps, we'll use the one feature of the WebAssist Framework Builder extension to dynamically insert the contents of the child page into the main page. Then, we'll add the necessary Ajax-related code via another feature of that extension.
Step 1: Connect main page to child page
In this step, we'll use a feature of Framework Builder to insert the child page into the main page. Note that this step will not insert the needed Ajax code—we'll do that in the next one.
- Place cursor in the <div id="childSelect"> tag.
- Choose WebAssist > Framework Builder > Plug-in > Insert Plug-in
- In the Framework: Insert Plug-in dialog, set Trigger to before page load and, for Plug-in Source, click the folder icon and navigate to the plugins folder and choose childSelect.php.
- Click OK.
The extension will insert code in two places in your HTML, as well as above the <html> tag. In addition to adding code within the <div> tag, it also adds a line of code just before the closing </head> tag. This code will bring in any code in the <head> section of the plugin page. In this case, doing so would repeat the <meta charset="UTF-8"> tag, so it's best to remove the inserted PHP code.
- Highlight the PHP code line directly above the closing </head> tag that starts " <?php echo((isset($WA_childSelect…" and delete it.
- Save your page.
Step 2: Add Ajax Functionality
Now it's time to bring Ajax into play. We'll use a Framework Builder feature found in Dreamweaver's Behavior panel, used for inserting client-side behaviors to the page.
- Select the <select id="towns"> tag.
- Choose Windows > Behaviors to open the Behaviors panel.
- From the Behaviors panel, choose WebAssist > Framework Builder > Load Plugin to Div.
- In the Load Plugin to Div dialog, set the following values:
- Submit form: forms[0]
- Plugin: plugins/childSelect.php
- Load into: div: childSelect
- Click OK.
- Save the page.
Dreamweaver will insert a script tag to load Ajax.js in the <head> section of the page as well as add an onChange attribute to the chosen <select> tag. When executed, this code will asynchronously—without refreshing the page—load the child select list into the main page, based on the option chosen from the parent select list. The coding is now complete and we're ready to test the page!
Step 3: Test your work
All right, you did it! Now, let's test your work!
- From the main.php page, click the Real-time Preview icon on the lower right of the document window and select your preferred browser.
- When the page displays, choose a town from the first select list.
- After the second select list populates, choose a team.
Note that the static option "Then select a team" is no longer visible after a town has been selected and the rsTeam recordset is not empty.
Congratulations! You've successfully used Data Bridge 2.0 to create dynamic drop-downs. The method we used to accomplish this is extremely powerful and can be used to power all sorts of Ajax functionality.
georgina_barrett_187762: 5 Years, 10 Months, 2 Weeks, 6 Days, 4 Hours, 27 Minutes ago
Clear and concise tutorial - I got it to work first time. Thank you.
: 3 Months, 1 Week, 3 Days, 5 Hours, 41 Minutes ago
How To Recover BITCOIN From Fake Cryptocurrency Investment // ULTIMATE HACKER JERRY
Prominent bitcoin recovery firm ULTIMATE HACKER JERRY focuses on recovering funds that have been taken from people by fraudulent investment sites. Using cutting-edge technology and years of industry experience, their team of experts tracks and traces stolen cryptocurrency, improving clients' chances of recovery. The recuperation process is impacted by lost minutes. Consult Captain ULTIMATE HACKER JERRY right away. Their cybersecurity team is made up of licensed professional blockchain developers with extensive expertise of the cryptocurrency field that can assist you with any cryptocurrency scam recovery, including recovering funds from bitcoin scams and investment scams.
Webpage; ultimatehackerjerry. co m Mail; contact@ultimatehackerjerry .c omText or Call ; + 1 (458) 308 (08 25