Jump to content

[RESOLVED] refresh select list with ajax


cinek

Recommended Posts

I want to reload/refresh a list box when a user clicks either on a button or legend (I'd prefer the legend)I wrote something like this, but it doesn't seem to work.

function reloadList(){	try {		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 	} catch(e){		alert("your browser sucks!");	}		xmlhttp.onreadystatechange = triggered;		xmlhttp.open("GET", "reload.php");		xmlhttp.send(null);		function triggered(){		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)){			document.getElementById('#configSelect').innerHTML = xmlhttp.responseText;		}	}}

reload.php has php code that gets a value from the db

<?php											mysql_connect('localhost', 'root', 'pass');		mysql_select_db('ipsum');	$sql = "SELECT Name FROM con";		$result = mysql_query($sql);		while($rows = mysql_fetch_array($result)){	$name = $rows[0];	echo "<option name=\"$name\">$name</option>";	}?>

any ideas how to fix this?edit: firebug is showing this error:document.getElementById("#configSelect") is null[break on this error] document.getElementById('#configSelect').value = xmlhttp.responseText;no idea why that is... here's the configSelect code

  <!-- Start load field -->						<fieldset id="loadField">							<legend id="loadLegend" onclick="reloadList()">Laduj</legend>							  <div id="loadForm">								<label for="loadConfig" id="loadConfigLbl">Laduj Konfiguracje</label>								<select id="configSelect">									<?php																				mysql_connect('localhost', 'root', 'pass');																				mysql_select_db('ipsum');																				$sql = "SELECT Name FROM con";																				$result = mysql_query($sql);																		while($rows = mysql_fetch_array($result)){											$name = $rows[0];											echo "<option name=\"$name\">$name</option>";										}									?>								</select>								<input type="button" value="Laduj" id="load" class="load" />							</div>						</fieldset>						<!-- End load field -->

Link to comment
Share on other sites

document.getElementById("#configSelect") is null
document.getElementById() doesn't use the # marker to indicate an ID. You should just use document.getElementById('configSelect')Also, I'm not sure that setting options in a select field using .value will work (although I could be wrong there).
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...