ho creato una funzione aggiornaSelect() che mi permetta di concatenare n select.
al onChange della select passo alla mia funzione aggiornaSelect() l'identificativo della select(numeroSelect) e quante sono le select nella pagina(totaleSelect).
ciclo per il numero totale di select e ogni volta richiamo ricerca() per fare aggiornare ogni select.
Codice PHP:
<script type="text/javascript">
function aggiornaSelect(numeroSelect,totaleSelect) {
var ricerca;
var contatore;
for (contatore=1;contatore<=totaleSelect;contatore++)
{
var parametro1='select'+numeroSelect;
var parametro2='resultsSelect'+contatore;
var parametro3='activityCage';
var parametro4='select'+contatore+'.php';
var par='select'+contatore;
alert(par+" "+$F(par))
if(contatore!=numeroSelect)
{
ricerca = new ricerca(parametro1,parametro2,parametro3,parametro4,totaleSelect);
}
else
{
if($F(par)==0) ricerca = new ricerca(parametro1,parametro2,parametro3,parametro4,totaleSelect);
}
}
}
</script>
Codice PHP:
// JavaScript Document
ricerca = Class.create();
ricerca.prototype = {
initialize: function(searchItem,resultsItem,activityItem,nomePagina,totaleSelect) {
this.searchItem = searchItem;
this.resultsItem = resultsItem;
this.activityItem = activityItem;
this.nomePagina = nomePagina;
this.nomeParametro = searchItem;
this.totaleSelect = totaleSelect;
this.injectBehavior();
this.updateSearchResults();
},
injectBehavior: function() {
//add key-up event observer to this.searchItem per aree di testo
//add change event observer to this.searchItem per tendine
Event.observe(
this.searchItem,
'change',
this.updateSearchResults.bindAsEventListener(this));
},
updateSearchResults: function() {
//only make the request if we're not in the middle of searching
if(Ajax.activeRequestCount == 0) {
var pars ="";
for (index=1;index<=this.totaleSelect;index++)
{
if(index==1) pars+='select'+index+'='+ $F('select'+index);
pars+= '&select'+index+'='+ $F('select'+index);
}
//var pars = this.nomeParametro + '=' + $F(this.searchItem);
var url = this.nomePagina;
//show the activity indicator
$(this.activityItem).style.display = '';
//make the ajax request
var myAjax = new Ajax.Request(url,{method: 'post',parameters: pars,onComplete: this.handleSearch.bind(this)});
}
},
handleSearch: function(originalRequest,id) {
//parse the results
$(this.resultsItem).innerHTML = originalRequest.responseText;
//hide the activity indicator
$(this.activityItem).style.display = 'none';
}
}
ora il tutto funziona e ne sono felicissimo, fino a che io non vado a commentare l'unico alert che ho messo nella funzione
Codice PHP:
// alert(par+" "+$F(par))
se commento questo alert mi viene aggiornata solo la prima select del ciclo...
qualcuno sā come aiutarmi???
da troppo poco mi cimento con ajax e javascript per farcela da solo...
Thanks all