/* _createAlbumFormat.php */
require_once("../serv/db.php");
if (!isset($_POST["idParent"]))
{
echo "[{err:\"Invalid Paramaters\", id:0}]";
exit;
}
if ( ($album_formats = mssql_query("exec sp_getAlbumFormats ". $_POST["idParent"])) )
{
$count = 0;
echo "[";
while ($row = @mssql_fetch_array($album_formats))
{
if ($count++ > 0)
echo " , ";
echo "{name:\"". addslashes($row[2]) ."\" , id:". $row[0] ."}";
}
echo "]";
} else
echo "{err:\"Error Occurred: ". addslashes(mssql_get_last_message()) ."\", id:0}";
mssql_close($db);
/* js function */
function populate_album_format(s, id)
{
// 's' should be a reference to 'idFormat' select node
if (s.options[s.selectedIndex].value == "")
return;
ajax.open("post", "inc/ajax/_getAlbumFormats.php", true);
ajax.send("idParent="+ s.options[s.selectedIndex].value);
var f_s = document.getElementById("idFormat"); // should be only 1
f_s.options.length = 0;
f_s.options[0] = new Option("Loading Album Formats For "+ s.options[s.selectedIndex].text +"....", null);
if (id != undefined)
ajax.idFormat = id;
ajax.onSuccess = function()
{
var i, len;
var arr = eval(this.data);
var f_s = document.getElementById("idFormat");
f_s.options.length = 0;
len = arr.length;
for (i = 0; i < len; i++)
{
f_s.options[i] = new Option(arr[i].name, arr[i].id);
if (this.idFormat != undefined && arr[i].id == this.idFormat)
f_s.options[i].selected = true;
}
if (this.idFormat != undefined)
this.idFormat = undefined;
else
f_s.focus(); // only focus the field if we're not reseting the form
}
}