SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: AJAX issue

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX issue

    I am injecting a select list into a div based on a selection in a different select list using AJAX. Everything is working great with one exception. The "name" attribute in the <select> tag of my injected list is not passed through to the browser. When I run the method that creates it sending it directly to the browser, rather than through AJAX it shows up fine. When I run it through AJAX, the list is injected perfectly, minus the "name" attribute. Needless to say, this screws up my POST.

    I can't figure out what is going on.

    Here is the jquery trigger code (Thanks to this list for helping me with this script):

    Code:
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.min.js"></script>
    
    <script type="text/javascript" language="javascript">
    
    	$(document).ready(function() {
    	  $("#creator").click(function(event){
    	  	var value= $('#creator option:selected').attr('value');
    	    $.get( 
             "_scripts/get_series_options.php",
             { series_id: value },
             function(data) {
                $('#series').html(data);
             }
    	
    	      );
    	  });
    	});
    	
    </script>
    Here is the php function it calls, sending the appropriate id variable to this function and returning the full select list generated from this variable (the "name" attribute is colored red so it will stand out):

    Code:
    public function get_series_option_list($id) {
    			
    			global $db;
    			global $data;
    			
    			$query = "SELECT tbl_series.series_name, tbl_series.series_id FROM tbl_series INNER JOIN tlink_creator_series ON  tbl_series.series_id = tlink_creator_series.series_id WHERE tlink_creator_series.creator_id = $id";
    	
    			//echo "\$query = $query";
    			
    			$result = $db->query($query) or die('Query Failed');
    			
    			$series = "<label for=\"series_values\">Choose a Series: <br/></label>\n";
    			$series .= "<select id=\"series_values\" name=\"series_id\" >\n";
    			
    			
    			
    			while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    			
    			$series .= "<option value=\"" . $row['series_id'] . "\">" . $row['series_name'] . "</option>\n";
    			
    			}
    			
    			$series .= '</select>';
    			echo $series;
    		
    		} // End get_series_option_list definition
    Here is the html (it is injected into the "series" div):

    Code:
    <div id="float">
    	<label for="creator">Choose a Creator: </label>
    	<select id="creator">
    	<option value="#" >Choose</option>
    	<option value="1" >Elsa</option>
    	<option value="2" >Sharon</option>
    	<option value="3" >Larry</option>
    	<option value="4" >Kenoli</option>
    	</select>
    	</div>
    	
    	<div id="series"></div>
    Here is what AJAX returns as displayed in firebug (note the missing "name" attribute in the <select> tag colored red to identify it):

    Code:
    <label for="series_values">
    Choose a Series:
    <br>
    </label>
    <select id="series_values">
    <option value="4">Emotional</option>
    <option value="5">Urban Landscape</option>
    <option value="6">Visionary</option>
    <option value="7">Whimsical</option>
    </select>
    Note also that the "id" attribute passes just fine.

    HELP! What is happening?????

    Thanks,

    --Kenoli

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved my problem. Sorry, was calling the wrong script.

    Thanks,

    --Kenoli


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
  •