CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #2
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: populating Drop down with items frmo server.

    The cleanest approach by far (in my opinion) is to only have PHP generate a delimited list of the options, and then programmatically add them to the list with JavaScript. You could for example separate items with commas:
    PHP Code:
    // Output comma-delimited list of items (assuming $items is an array.)
    die(implode(","$items)); 
    Then in JavaScript you would add it programmatically:
    Code:
    var items = request.responseText.split(",");
    for (var i = 0; i < items.length; i++) {
        // ...
    }
    If you want it to be true AJAX (Asynchronous JavaScript and XML), you could generate an XML response (and use the responseXml property):
    Code:
    <?xml version="1.0"?>
    <items>
      <item>Item One</item>
      <item>Item Two</item>
    </items>
    In any case, I don't like the idea of generating HTML in one application and just blindly inserting it into another (using innerHTML.)
    Last edited by andreasblixt; September 26th, 2007 at 07:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured