Dynamic population of drop down


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Dynamic population of drop down

  1. #1
    Join Date
    Oct 2006
    Posts
    2

    Dynamic population of drop down

    Hello All,

    I am very new to AJAX and am trying to use it in a web application that I am working on. I need some guidance from the experts.

    Here is the scenario:

    Initially, the user logs onto the application and goes to the product selection screen. (Please see ProductSelection.png file attached).

    The product selection screen has two drop downs, one for the Carrier ID and the other for Product Name.

    I would like to use AJAX to dynamically populate the Product Name drop down list depending upon the Carrier ID selected by the user.

    How can this be done in AJAX? I would really appreciate if someone can point me in the right direction.

    Thanks in advance.

    Regards,
    Kunal
    Attached Images Attached Images

  2. #2
    Join Date
    Apr 2007
    Posts
    2

    Here's a direction to go in...

    I'm by no means an AJAX expert, but I've been populating dropdowns for a while. On the back end, I send out a stream of data with a bar ("|") separating the values. Then, on the input, I parse the values out using the 'split' function. Works pretty well, althgouh I'm having problems with doing this to a parent window right now.. but that's probably more than you're doing anyway.
    -- John (code below)

    function getvals(inputfield) {
    lcField = inputfield.name;
    // lnAt = lcField.lastIndexOf('PGF_');
    //Hard coded the removal of 'PGF_Px_'
    lnAt = 7;
    lcArray = lcField.substr(lnAt); //Have to allow for different suffixes
    targetlb = document.getElementById(lcField);
    // lcList = targetlb.value;
    lcList = targetlb.options[targetlb.selectedIndex].innerHTML;
    // alert(targetlb.value);
    oldurl = document.wwForm.action;
    lnAt2 = oldurl.indexOf('?');
    lnAt2 = lnAt2 - 3;
    lcSuffix = oldurl.substr(lnAt2, 3); //Have to allow for different suffixes

    var url;
    url = 'getvals.' + lcSuffix + '?which=la_' + lcArray + '&curval=' + lcList;
    lcDate = new Date();

    var dmed = url.split('?');
    url = dmed[0] + '?time=' + lcDate.valueOf() + '&' + dmed[1];


    if (targetlb.length > 1) {
    return true;
    } else {
    targetlb.length=0;
    targetlb.options[0] = new Option("Retrieving.......","");
    loadXMLDoc(url);
    }
    }

    var req;
    var targetlb;
    var targettb;

    function processReqChange () {
    if ((req.readyState == 4) && (req.status == 200)) {
    response = req.responseText;
    var d = response.split('|');
    targetlb.length=0;
    if (d.length > 0) {
    for (i=0; i < d.length; i++) {
    opttext = d[i];
    optvalue = d[i];
    targetlb.options[i] = new Option(opttext,optvalue );
    }
    } else {
    targetlb.options[0] = new Option("No Values","");
    }
    }
    else {
    }
    }

    function processReq4Value () {
    if ((req.readyState == 4) && (req.status == 200)) {
    response = req.responseText;

    var d = response.split('|');
    targettb.value=lcList;
    if (d.length > 0) {
    for (i=0; i < d.length; i++) {
    opttext = d[i];
    // targettb.value = opttext;
    }
    } else {
    targettb.value = "No Values";
    }
    }
    else {
    }
    }

    function getXMLHTTP(){
    var A=null;
    try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
    }catch(e){
    try{
    A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
    A=null
    }
    }
    if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()
    }
    return A
    }
    function loadXMLDoc(url) {
    req=getXMLHTTP();
    if(req){
    req.onreadystatechange = processReqChange;
    req.open("GET", url, true);
    req.send(null);
    }
    }
    function loadXMLValue(url) {
    req=getXMLHTTP();
    if(req){
    req.onreadystatechange = processReq4Value;
    req.open("GET", url, true);
    req.send(null);
    }
    }

Similar Threads

  1. Dynamic Columns & Dynamic Grouping ???
    By ngambhava in forum Database
    Replies: 1
    Last Post: 01-03-2007, 03:15 PM
  2. Ajax browser and drop down menu problem
    By blckspder in forum AJAX
    Replies: 1
    Last Post: 11-22-2006, 03:19 PM
  3. Replies: 0
    Last Post: 08-05-2005, 04:14 PM
  4. Drag and Drop Problem
    By Xin Li in forum .NET
    Replies: 0
    Last Post: 03-13-2002, 05:03 AM
  5. DROP TABLE @VariableName
    By John C. Gunvaldson in forum Database
    Replies: 4
    Last Post: 10-19-2000, 12:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center