SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Regina, SK
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Starting out with AJAX

    I'm finally playing with some AJAX, and have some of it working. However, I'm trying to populate the options of a select in my form.

    So, in part of my html document I have the following:


    HTML Code:
    <form name="select_album">
      <select id="album_list" name="albumid" onChange="getSongs();" >
      </select>
    </form>
    Now, in the javascript that is to populate the options:
    Code:
    function getAlbums() {
            http.open('get', 'show_albums.php?id='
                            + document.select_artist.artistid.value);
            http.onreadystatechange = handleAlbums;
            http.send(null);
    }
    
    
    
    function handleAlbums() {
            if(http.readyState == 4){ //Finished loading the response
                    var response = http.responseText;
                    document.getElementById('album_list').innerHTML = response;
            }
    }
    This all seems to work, except show_albums.php returns a list of albums with the option tags:
    HTML Code:
    <option>Option 1</option>
    <option>Option 2</option>
    The problem is, using a DOM Inspector (in Firefox) it appears that my Options are being inserted, but without the Option tags, so I get something like:
    HTML Code:
    <form name="select_album">
      <select id="album_list" name="albumid" onChange="getSongs();" >
        Option 1Option 2
      </select>
    </form>


    Any suggestions?

    EDIT : I used View Generated Source, from the Web Developer Toolbar for Firefox, and yes, that is exactly what is happening. Its stripping out the HTML. Yet, the same code in a different part of the page does not. I'm guessing it has something to do with being inside the select, but I'm not sure what.
    Reduce or eliminate spam on your sites without CAPTHCAs
    - maybe it is possible: http://formantispam.thekerrs.ca/

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,237
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    DOM form elements

    I haven't tried it yet, but I read recently of the need to use getItem for form elements because getElement doesn't work (might be only for GreaseMonkey ???). But in any case I think you should at least try using DOM syntax in place of
    document.select_artist.artistid.value

  3. #3
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Regina, SK
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I did do some renaming, no change, but I did get it working. Instead of having show_albums.php return only the options, I changed it so it returns the entire form into some div tags. Works great.
    Reduce or eliminate spam on your sites without CAPTHCAs
    - maybe it is possible: http://formantispam.thekerrs.ca/


Bookmarks

Posting Permissions

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