ciao,
sto provando la soluzione ajax: questo è il codice della finestra principale con il form
codice:
<?php include("../connection.php"); ?>
<?php
//query for the filter form (tabel resource)
$query = "SELECT name FROM resource";
//execute query
$result = mysql_query($query, $con);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
?>
<html>
<head>
<title>User Editor (EACS)</title>
<link rel=stylesheet href="../style.css" type="text/css">
<script type="text/javascript">
var http = createRequestObject();
var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
function addElement(ogg,val,text){
var newOption;
newOption = document.createElement("option");
newOption.value = val;
newOption.text = text;
ogg.add(newOption, where);
}
function removeElement(ogg){
if(ogg.options.length > 0){
while (ogg.options.length) {
ogg.remove(0);
}
}
}
function disabledElement(ogg,val){
document.getElementById(ogg).disabled = val;
}
function loadingAttributes(oggId){
var res = document.getElementById(oggId).value;
//alert('getAttributes.php?res=' + res);
http.open('GET','getAttributes.php?res=' + res, true);
http.onreadystatechange = getAttributes;
http.send(null);
}
function getAttributes(){
var Attribute = document.getElementById('filter2');
removeElement(Attribute);
id = document.getElementById('filter1').value;
if(id == 'filter1'){
disabledElement('filter2',true);
addElement(Attribute,'sel','Select a resource before:');
}else{
if(http.readyAttribute == 4){
if (http.status == 200) {
var response = http.responseText;
if(response == ''){
disabledElement('filter2',true);
addElement(Attribute,'sel','No Attributes');
}else{
removeElement(Attribute);
coppia = response.split(',');
max = coppia.length;
addElement(Attribute,'sel','Select a resource:');
for(x=0;x<max;x++){
val = coppia[x];
addElement(Attribute,val,val);
}
disabledElement('filter2',false);
}
}
}else{
addElement(Attribute,'sel','Loading...');
}
}
}
</script>
<body>
<div id="form">
<form id="form1" name="form1" method="post" action="">
<select name="filter1" id="filter1" onchange="loadingAttributes('filter1');">
<option value="">---</option>
<?php while ($row = mysql_fetch_assoc($result)) {?>
<option value="<?php echo $row['name'];?>"><?php echo $row['name'];?></option>
<?php } ?>
</select>
.
<select name="filter2" id="filter2">
<option value="">---</option>
</select>
</form>
</div>
</body>
</html>
Mentre la pagina php che interroga il db e mi ritorna gli attributi e la seguente:
Codice PHP:
getAttributes.php
<? include("../connection.php");
//load resource name
$resource = $_REQUEST['res'];
//query for the filter form (tabel resource)
$query = "SELECT attributes FROM resource WHERE name ='$resource'";
//execute query
$result = mysql_query($query, $con);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$attributes="";
while ($row = mysql_fetch_assoc($result)) {
$attributes = $row['attributes'];
}
echo $attributes;
?>
Il problema è che http.readyAttribute mi ritorna "undefined", cosa può essere?