Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di torrone
    Registrato dal
    Apr 2006
    residenza
    Padova
    Messaggi
    1,128

    popolare select con javacript

    ho bisogno di replicare una select creata con un ciclo for in php anche in javascript.

    Esempio:

    PHP

    Codice PHP:
            <select name="calcIntDayIni[]">    <option value="0" SELECTED="SELECTED">Giorno</option>        <?php        for($dayS=1;$dayS<=31;$dayS++){            $dayS sprintf("%02d"$dayS); // porto tutto a doppia cifra 1 --> 01            echo "<option value='{$dayS}'>{$dayS}</option>";    }        ?>        </select>
    Devo poterlo riprodurre in javascript completamente, quindi creare questa select completamente.

    Come posso fare?

  2. #2
    Utente bannato
    Registrato dal
    Apr 2009
    Messaggi
    530
    codice:
    <script type="text/javascript">
    
    function popolaSelect(){
     
     var theOptions='';
    
     for(g=1; g<=31; g++){
         if(g<10){g='0' + g;
         };
     theOptions = theOptions + '\n<option value="' + g + '">' + g + '<\/option>';
     }
    
     document.getElementById("dove").innerHTML=
     '<select name="calcIntDayIni[]"><option value="0" selected="selected">Giorno<\/option>' + theOptions + '<\/select>';
     }
    
    </script>
    
    <body onload="popolaSelect();">
    
    <form>
    <span id="dove"></span>
    
    <form><input onclick="w=window.open(); 
           w.document.write('<textarea cols=\'90\' rows=\'24\'>' + document.getElementById('dove').innerHTML + '<\/textarea>');" 
           value="see code" type="button"
          >
    </body>

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.