| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
||||||||||||||
|
||||||||||||||
|
AJAX / ASP Dependent Dropdown
Here is an example of a Dependent Dropdown using Pure ASP.
The addition here is that it also implements AJAX (xmlHTTP) to call the script dynamically without submitting/refreshing the page. Here is the basic script without any major validation, error messages or other form elements. http://computer-helpforum.com/asp/a...nt_dropdown.asp The example uses car manufacturers and models Here is the the first dropdown using a standard recordset loop to popuplate the dropdown. asp Code:
Three main features of this code are Code:
onchange="ajaxcombo('sMan','content_model')
This is the Ajax code that calls the dynamic script to populate the second dropdown. Code:
<noscript><input type="submit" name="GetModels" value="Get Models"></noscript> This code shows a submit button if Javascript (AJAX) is disabled. Code:
<span id="content_model"><%Call getModels(sMan)%></span> This calls the Sub that populates the second dropdown. asp Code:
This is the Sub to populate the second dropdown. It takes the ID of the Manufacturer submitted to get the associated models. The script will work using Pure ASP and HTML. If you want to add the AJAX functionallity then you need a Javascript. The example here is taken from http://www.dynamicdrive.com/dynamic...ajaxcontent.htm asp Code:
Code:
url = '<%=Request.ServerVariables("SCRIPT_NAME")%>?method=ajax&sMan=' + selectobj.options[selectobj.selectedIndex].value;
When the script it called it will take the value of the select and append it to the URL. It will then call the Sub dynamically (in the background). asp Code:
If the AJAX script is called then this code will detect it, call the Sub and return the populated dropdown HTML. The AJAX script will then replace the HTML dynamically in the webpage. The full script can be seen below. The script and database are attached.
__________________
CyberTechHelp |
|
#2
|
|||
|
|||
|
This is the full script for the Ajax Dependent Dropdown. Also added is a recordset to display the model details when the model is chosen. asp Code:
|