Salve a tutti,
premetto che di Ajax ne so pochissimo... ho questo script che funziona perfettamente...
dovrei inviare un secondo valore relativo a subcat. Come posso fare?Codice PHP:
<script type="text/javascript">
function AjaxFunction(cat_id)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateck()
{
if(httpxml.readyState==4)
{
var myarray=eval(httpxml.responseText);
// Before adding new we must remove previously loaded elements
for(j=document.testform.subcat.options.length-1;j>=0;j--)
{
document.testform.subcat.remove(j);
}
for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
//optn.value = myarray[i];
document.testform.subcat.options.add(optn);
}
}
}
var url="dd.php";
url=url+"?cat_id="+cat_id;
url=url+"&sid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
}
</script>
<form name="testform" method='POST' action='mainck.php'>
Categoria
<select name=cat onChange="AjaxFunction(this.value);">
<option value=''><-- Seleziona --></option>
<?php
require "config.php";// connection to database
$q=mysql_query("select * from hcat_it ");
while($n=mysql_fetch_array($q)){
echo "<option value=$n[idcat]>$n[categoria]</option>";
}
}
?>
</select>
<select name=subcat>
</select>
<input name=objectID type=hidden value=objectID /><input type=submit value=CERCA>
</form>
Da categoria passo a sottocategoria ma nel passaggio finale ho bisogno di avere sia il nome della sottocategoria che un valore numerico per mysql.
Posso intervenire in questa pagina lavorando su Ajax?
Grazie mille.

Rispondi quotando