Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    eliminare un option da select

    Ciao a tutti,
    non riesco a capire come mai non funziona...

    Praticamente mi carica correttamente i numeri da 1 a 28, poi dovrebbe eliminare tutti lasciando solo vuoto,7,14,21,28 mentre mi lascia vuoto,7,14,21,28,8,12,16,20,24,28.

    COME MAI?

    Non riesco a capire il problema.

    Fatemi sapere.

    Grazie mille!


    codice:
    if ((dataselezione>datacontrollo1)&&(dataselezione<datacontrollo2)) {
        option0 = new Option("",0)
        option1 = new Option("1",1)
        option2 = new Option("2",2)
        option3 = new Option("3",3)
        option4 = new Option("4",4)
        option5 = new Option("5",5)
        option6 = new Option("6",6)
        option7 = new Option("7",7)
        option8 = new Option("8",8)
        option9 = new Option("9",9)
        option10 = new Option("10",10)
        option11 = new Option("11",11)
        option12 = new Option("12",12)
        option13 = new Option("13",13)
        option14 = new Option("14",14)
        option15 = new Option("15",15)
        option16 = new Option("16",16)
        option17 = new Option("17",17)
        option18 = new Option("18",18)
        option19 = new Option("19",19)
        option20 = new Option("20",20)
        option21 = new Option("21",21)
        option22 = new Option("22",22)
        option23 = new Option("23",23)
        option24 = new Option("24",24)
        option25 = new Option("25",25)
        option26 = new Option("26",26)
        option27 = new Option("27",27)
        option28 = new Option("28",28)
        document.mioform2.ricercanotti.options[0]=option0
        document.mioform2.ricercanotti.options[1]=option1
        document.mioform2.ricercanotti.options[2]=option2
        document.mioform2.ricercanotti.options[3]=option3
        document.mioform2.ricercanotti.options[4]=option4
        document.mioform2.ricercanotti.options[5]=option5
        document.mioform2.ricercanotti.options[6]=option6
        document.mioform2.ricercanotti.options[7]=option7
        document.mioform2.ricercanotti.options[8]=option8
        document.mioform2.ricercanotti.options[9]=option9
        document.mioform2.ricercanotti.options[10]=option10
        document.mioform2.ricercanotti.options[11]=option11
        document.mioform2.ricercanotti.options[12]=option12
        document.mioform2.ricercanotti.options[13]=option13
        document.mioform2.ricercanotti.options[14]=option14
        document.mioform2.ricercanotti.options[15]=option15
        document.mioform2.ricercanotti.options[16]=option16
        document.mioform2.ricercanotti.options[17]=option17
        document.mioform2.ricercanotti.options[18]=option18
        document.mioform2.ricercanotti.options[19]=option19
        document.mioform2.ricercanotti.options[20]=option20
        document.mioform2.ricercanotti.options[21]=option21
        document.mioform2.ricercanotti.options[22]=option22
        document.mioform2.ricercanotti.options[23]=option23
        document.mioform2.ricercanotti.options[24]=option24
        document.mioform2.ricercanotti.options[25]=option25
        document.mioform2.ricercanotti.options[26]=option26
        document.mioform2.ricercanotti.options[27]=option27
        document.mioform2.ricercanotti.options[28]=option28
    }
    else
    {
        option0 = new Option("",0)
        option7 = new Option("7",7)
        option14 = new Option("14",14)
        option21 = new Option("21",21)
        option28 = new Option("28",28)
        document.mioform2.ricercanotti.options[0]=option0
        document.mioform2.ricercanotti.options[1]=option7
        document.mioform2.ricercanotti.options[2]=option14
        document.mioform2.ricercanotti.options[3]=option21
        document.mioform2.ricercanotti.options[4]=option28
        document.mioform2.ricercanotti.options[5]=null
        document.mioform2.ricercanotti.options[6]=null
        document.mioform2.ricercanotti.options[7]=null
        document.mioform2.ricercanotti.options[8]=null
        document.mioform2.ricercanotti.options[9]=null
        document.mioform2.ricercanotti.options[10]=null
        document.mioform2.ricercanotti.options[11]=null
        document.mioform2.ricercanotti.options[12]=null
        document.mioform2.ricercanotti.options[13]=null
        document.mioform2.ricercanotti.options[14]=null
        document.mioform2.ricercanotti.options[15]=null
        document.mioform2.ricercanotti.options[16]=null
        document.mioform2.ricercanotti.options[17]=null
        document.mioform2.ricercanotti.options[18]=null
        document.mioform2.ricercanotti.options[19]=null
        document.mioform2.ricercanotti.options[20]=null
        document.mioform2.ricercanotti.options[21]=null
        document.mioform2.ricercanotti.options[22]=null
        document.mioform2.ricercanotti.options[23]=null
        document.mioform2.ricercanotti.options[24]=null
        document.mioform2.ricercanotti.options[25]=null
        document.mioform2.ricercanotti.options[26]=null
        document.mioform2.ricercanotti.options[27]=null
        document.mioform2.ricercanotti.options[28]=null
    }

  2. #2
    Proposta:

    Codice PHP:
    if ((dataselezione>datacontrollo1)&&(dataselezione<datacontrollo2)) {
        
    opts.push(new Option("",0));
        
    opts.push(new Option("1",1));
        
    opts.push(new Option("2",2));
        
    opts.push(new Option("3",3));
        
    opts.push(new Option("4",4));
        
    opts.push(new Option("5",5));
        
    opts.push(new Option("6",6));
        
    opts.push(new Option("7",7));
        
    opts.push(new Option("8",8));
        
    opts.push(new Option("9",9));
        
    opts.push(new Option("10",10));
        
    opts.push(new Option("11",11));
        
    opts.push(new Option("12",12));
        
    opts.push(new Option("13",13));
        
    opts.push(new Option("14",14));
        
    opts.push(new Option("15",15));
        
    opts.push(new Option("16",16));
        
    opts.push(new Option("17",17));
        
    opts.push(new Option("18",18));
        
    opts.push(new Option("19",19));
        
    opts.push(new Option("20",20));
        
    opts.push(new Option("21",21));
        
    opts.push(new Option("22",22));
        
    opts.push(new Option("23",23));
        
    opts.push(new Option("24",24));
        
    opts.push(new Option("25",25));
        
    opts.push(new Option("26",26));
        
    opts.push(new Option("27",27));
        
    opts.push(new Option("28",28));
    }
    else
    {
        
    opts.push(new Option("",0));
        
    opts.push(new Option("7",7));
        
    opts.push(new Option("14",14));
        
    opts.push(new Option("21",21));
        
    opts.push(new Option("28",28));
    }

    var 
    sel document.mioform2.ricercanotti;

    for(var 
    sel.firstChild!= nullc.nextSibling){
       
    c.removeNode(true);
    }
    for(var 
    0opts.lengthi++){
       
    sel.appendChild(opts[i]);

    comunque, metti SEMPRE il ; alla fine di ogni istruzione, che l'interprete JS cerca di capire da solo dove finiscono le istruzioni, ma è un software, mica è infallibile.
    I DON'T Double Click!

  3. #3
    Concordo col ; anche se non va comunque...

    Come mai hai scritto: codice PHP: ??!?

    Comunque di pomeriggio provo, speriamo bene... se da problemi riscrivo!

    Grazie mille!

  4. #4
    ho usato il BBCode di PHP perché colora il codice, quello è Javascript non preoccuparti
    I DON'T Double Click!

  5. #5
    ok per il discorso php!

    ..mi va in errore! Ma il codice non è completo... giusto?
    Nel senso che l'oggetto che dev'essere modificato non è indicato..

  6. #6
    come no?

    codice:
    var sel = document.mioform2.ricercanotti;
    ho dato per scontato che avessi un form con name="mioform2" contenente una select con name="ricercanotti".

    inoltre devi avere 3 variabili definite:

    dataselezione
    datacontrollo1
    datacontrollo2

    io ho preso l'esempio che hai dato tu, davo per scontato che i nomi delle variabili andassero bene
    I DON'T Double Click!

  7. #7
    Si, ho tutto quello che hai indicato... però va in errore.

    Questa la funzione completa:

    codice:
    function selected(cal, date) {
      cal.sel.value = date; // just update the date in the input field.
      if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel2" || cal.sel.id == "sel3"))
        cal.callCloseHandler();
    	
    	x=new Array();
    	x=date.split("/");	 
        dataselezione= new Date(Date.UTC(x[2],(x[1]-1),x[0],0,0,0));
        timeselezione=Date.parse(dataselezione);
        datacontrollo1= new Date(Date.UTC(2009,09,31,0,0,0));
        timecontrollo1=Date.parse(datacontrollo1);
        datacontrollo2= new Date(Date.UTC(2010,04,29,0,0,0));
        timecontrollo2=Date.parse(datacontrollo1);
    	if ((dataselezione>datacontrollo1)&&(dataselezione<datacontrollo2)) { 
    		opts.push(new Option("",0)); 
    		opts.push(new Option("1",1)); 
    		opts.push(new Option("2",2)); 
    		opts.push(new Option("3",3)); 
    		opts.push(new Option("4",4)); 
    		opts.push(new Option("5",5)); 
    		opts.push(new Option("6",6)); 
    		opts.push(new Option("7",7)); 
    		opts.push(new Option("8",8)); 
    		opts.push(new Option("9",9)); 
    		opts.push(new Option("10",10)); 
    		opts.push(new Option("11",11)); 
    		opts.push(new Option("12",12)); 
    		opts.push(new Option("13",13)); 
    		opts.push(new Option("14",14)); 
    		opts.push(new Option("15",15)); 
    		opts.push(new Option("16",16)); 
    		opts.push(new Option("17",17)); 
    		opts.push(new Option("18",18)); 
    		opts.push(new Option("19",19)); 
    		opts.push(new Option("20",20)); 
    		opts.push(new Option("21",21)); 
    		opts.push(new Option("22",22)); 
    		opts.push(new Option("23",23)); 
    		opts.push(new Option("24",24)); 
    		opts.push(new Option("25",25)); 
    		opts.push(new Option("26",26)); 
    		opts.push(new Option("27",27)); 
    		opts.push(new Option("28",28)); 
    	} 
    	else 
    	{ 
    		opts.push(new Option("",0)); 
    		opts.push(new Option("7",7)); 
    		opts.push(new Option("14",14)); 
    		opts.push(new Option("21",21)); 
    		opts.push(new Option("28",28)); 
    	} 
    	
    	var sel = document.mioform2.ricercanotti; 
    	
    	for(var c = sel.firstChild; c != null; c = c.nextSibling){ 
    	   c.removeNode(true); 
    	} 
    	for(var i = 0; i < opts.length; i++){ 
    	   sel.appendChild(opts[i]); 
    	}
    }

  8. #8

  9. #9
    questo va in errore:

    codice:
    opts.push(new Option("",0));

  10. #10
    prova così:
    fuori dalla funziome metti:

    codice:
    var CreateOption = function(text, value){
    	var opt = document.createElement("option");
    	opt.value = value;
    	opt.appendChild(document.createTextNode(text));
    	return opt;
    }
    poi nella funzione:
    codice:
    var opts = [];
    if ((dataselezione>datacontrollo1)&&(dataselezione<datacontrollo2)) {
        opts.push(CreateOption("",0));
        opts.push(CreateOption("1",1));
        opts.push(CreateOption("2",2));
        opts.push(CreateOption("3",3));
        opts.push(CreateOption("4",4));
        opts.push(CreateOption("5",5));
        opts.push(CreateOption("6",6));
        opts.push(CreateOption("7",7));
        opts.push(CreateOption("8",8));
        opts.push(CreateOption("9",9));
        opts.push(CreateOption("10",10));
        opts.push(CreateOption("11",11));
        opts.push(CreateOption("12",12));
        opts.push(CreateOption("13",13));
        opts.push(CreateOption("14",14));
        opts.push(CreateOption("15",15));
        opts.push(CreateOption("16",16));
        opts.push(CreateOption("17",17));
        opts.push(CreateOption("18",18));
        opts.push(CreateOption("19",19));
        opts.push(CreateOption("20",20));
        opts.push(CreateOption("21",21));
        opts.push(CreateOption("22",22));
        opts.push(CreateOption("23",23));
        opts.push(CreateOption("24",24));
        opts.push(CreateOption("25",25));
        opts.push(CreateOption("26",26));
        opts.push(CreateOption("27",27));
        opts.push(CreateOption("28",28));
    }
    else
    {
        opts.push(CreateOption("",0));
        opts.push(CreateOption("7",7));
        opts.push(CreateOption("14",14));
        opts.push(CreateOption("21",21));
        opts.push(CreateOption("28",28));
    }
    
    var sel = document.mioform2.ricercanotti;
    
    while(sel.childNodes.length){
      var tmp = sel.childNodes[0];
      sel.removeChild(tmp);
      delete tmp;
    }
    for(var i = 0; i < opts.length; i++){
       sel.appendChild(opts[i]);
    }
    così dovrebbe andare bene
    I DON'T Double Click!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.