AJAX-populated form not sending new data!

Discussion in 'JavaScript' started by Kimochi, Oct 8, 2008.

  1. #1
    I'm loading data into some select lists, and they're displayed on the page properly. However, javascript cannot access the news values and neither can any 'action' page.

    The form
    
    <form name="frm_locations" method="post" action="manage_locations.php" enctype="multipart/form-data">
    				 <tr>
    					<td height="8" colspan="9"></td>
                    </tr>
    				<tr>
    					<td class="accinfo-block-col01" align="left">Country: </td>		
    					
    					<td colspan="2" class="accinfo-block-col02-span">
    					<?php countries($country);?>
    					</td>
    				</tr>
    				 <tr>
                        <td height="10" colspan="8"></td>
                    </tr>
    				<tr>
    					<td class="accinfo-block-col01" align="left">State: </td>		
    					
    					<td colspan="2" class="accinfo-block-col02-span" id="statespan">
    					<?php states($countryid,$state);?>
    					</td><td>If Other please Specify</td>
    					<td><input type="text" name="otherstate"/></td>
    					<td colspan="2">&nbsp;</td>
    				</tr>
    				 <tr>
                        <td height="10" colspan="8"></td>
                    </tr>
    				<tr>
    					<td class="accinfo-block-col01" align="left">City: </td>
    					<td id="cityspan"><?php cities($state,$city,$country);?>
    					
    					</td><td>&nbsp;</td>
    					<td>If Other please Specify</td>
    					<td><input type="text" name="othercity"/></td>
    					<td colspan="2">&nbsp;</td>
    				</tr>
                    <!--
    					<tr>
    					<td class="accinfo-block-col01" align="left">Area: </td>		
    					
    					
    					<td  id="areaspan"><?php areas($country,$state,$city); 
    					 
    					?>
    					
    					</td><td>&nbsp;</td>
    					<td>If Other please Specify</td>
    					<td><input type="text" name="otherarea"/></td>
    					<td colspan="2">&nbsp;</td>
    				</tr>-->
    				<tr>
    					<td class="accinfo-block-col01">&nbsp; </td>				
    				</tr>
                    <tr>
                        
                        <td colspan="7">
    						<table width="100%" border="0" cellspacing="0" cellpadding="0">
    							<tr>
    								<td width="70%" align="center" >
    									<input type="submit" name="btn_location" value="Add" class='button-normal'>
    								</td>
    							</tr>
    						 </table>
    						
    						</td>
    					 </tr>
    				</table>
    				 </form>
    
    Code (markup):

    Used to create AJAX-driven query (tested and working).
    
    function getState() {
    
         var countryid = document.getElementById("country").value;
    
    	
    
    	 var url ="get_state.php?countryid=" +countryid;
    
    	 request.open("GET", url, true);
    
         request.onreadystatechange =updatestate ;
    
         request.send(null);
    
       }
    
      
    
       function updatestate() {
    
         if (request.readyState == 4) {
    
    		if(request.status == 200){
    
           var exInfo = request.responseText;
    
    	  			document.getElementById("statespan").innerHTML = "<select name='state' id='state' class='black8' onchange='getcity();' >"+exInfo+"</select>";
    
    				
    
    		 }
    
         }
    
       }
    
       function getcity() {
    
         var stateid = document.getElementById("state").value;
    
    	 var url ="get_city.php?stateid=" +stateid;
    
    	 request.open("GET", url, true);
    
         request.onreadystatechange =updatecity ;
    
         request.send(null);
    
       }
    
      
    
       function updatecity() {
    
         if (request.readyState == 4) {
    
    	   if(request.status == 200){
    
           var exInfo = request.responseText;
    		document.getElementById("cityspan").innerHTML =exInfo;
    				
    
    		 }
    
         }
    
       }
    
    Code (markup):

    Used to retrieve information (tested and working).
    
    <?
    include_once("../includes/MySQLDB.php");
    include_once("../includes/table.macro.php");
    
    $conn = new MySQLDB();
    $conn->getConnection();				//start database connection
    
    $stateid=$_REQUEST['stateid'];
    
    $SQLstateInfo ="select CityID,City from Cities  C, States S where C.StateID=S.StateID and S.State='$stateid'  order by City";
    $city_options=$conn->executeQueryAsArray($SQLstateInfo);
    		  if (!$city_options){
    		$CityInfo="<input  type ='text' name='city'  class='input' size='10'>";
    		  }
    	        else
    			{
    				$CityInfo="<select name='city' id='city' class='black8'>";
    				$CityInfo.= "<option value='0'>Select City</option>";
    				foreach ($city_options as $value)
                    { 
    				$CityInfo.="<option value='$value[City]' >$value[City]</option>";
    				}
    				$CityInfo.="</select>";
    			}
    			$CityInfo.='asdasdasdasdasdasd';
    		echo $CityInfo;
    $conn->closeConnection();
    ?>
    
    Code (markup):
    Any suggestions? Thanks a lot for your help!
     
    Kimochi, Oct 8, 2008 IP
  2. Kimochi

    Kimochi Peon

    Messages:
    31
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Firebug indicated that the updates select lists don't belong to any form, despite being within the "frm_locations" form.
     
    Kimochi, Oct 8, 2008 IP