Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Select con immagine

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    437

    Select con immagine

    Ciao ragazzi!
    girando sul forum ho trovato lo script di cui ho bisogno pero ho una domanda.
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"
    <
    html
    <
    head
    <
    title>Untitled Document</title
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8"
    <
    script language="JavaScript" type="text/JavaScript"
    function 
    preloadImgs(args) { 
        for(var 
    n=0;n<arguments.length;n++) { 
            
    preloadImg(arguments[n]); 
        }     
        
    //funzione che precarica un immagine 
        
    function preloadImg(percorso) { 
            var 
    temp=new Image(); 
            
    temp.src=percorso
        } 

    function 
    _removeChild(parent,child){ 
        if(
    child != null){ 
            
    parent.removeChild(child); 
        } 
    }; 
    function 
    changeImg(el){ 
        var 
    ext'.png'
        var 
    targetdocument.getElementById("target"); 
        if(!
    target){return;} 
         var 
    optionValue el.options[el.selectedIndex].value
        var 
    currentImageoptionValue.concat(ext); 
        var 
    img document.createElement("img"); 
        
    img.srccurrentImage
        var 
    tmptarget.getElementsByTagName('img').item(0); 
        
    _removeChild(target,tmp); 
        
    target.appendChild(img); 

    window.onload = function(){ 
        
    preloadImgs('cod2.png','cod4.png','cod6.png','cod8.png'); 
        var 
    sel document.getElementById("my-select"); 
        
    sel.onchange=function(){ 
            
    changeImg(sel);  
        } 

    </script> 

    </head> 

    <body> 
    <form id="frm" action="" method="post"> 
    <select name="myselect" id="my-select" size="1"> 
        <option value ="cod2">Call of Duty 2</option> 
          <option value ="cod4">Call of Duty 4</option> 
          <option value ="cod6">Call of Duty MW2</option> 
          a<option value ="cod8">Call of Duty MW3</option> 
    </select> 
    </form> 
    <div id="target"></div> 
    </body> 
    </html> 
    E possibile far caricare una delle immagini all'apertura della pagina senza dover selezionare?

  2. #2
    Mettila nell'HTML...
    Nel div con id "target"

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    437
    facendo cosi poi non compare doppia?

  4. #4
    no, verrà rimossa.

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    437
    Grandioso. Funziona! grazie.

    Posso chiederti anche un'altra cosa.

    Ho questo script sempre recuperato in giro per internet che mi dovrebbe calcolare un preventivo spesa.

    Codice PHP:

    <form method="post" action="cart.php">

    <
    input type="hidden" name="gioco" value="Call of Duty">

     

    <
    div align=center><table><tr><td>[b]Game[/b]</td><td>

    <
    select name="game" id="gametype" onChange="changePrice();" style="width:175px">

                                    <
    option value="cod2">Call of Duty 2</option>

                                      <
    option value="cod4">Call of Duty 4</option>

                                    <
    option value="cod5">Call of Duty 5</option>

                                    <
    option value="cod6">Call of Duty 6</option>

                                    <
    option value="cod8">Call of Duty MW3</option>

                                    <
    option value="cs">Counter Strike</option>

                                    <
    option value="css">Counter StrikeSource</option>

                                    <
    option value="css">San Andreas MP</option>

     

                        </
    select></td></tr><tr><td>

                        [
    b]Slots[/b]</td><td>

                        <
    select name="player" id="player" onChange="changePrice();" style="width:175px">

                                    <
    option value="10">10 Slots</option>

                                    <
    option value="12">12 Slots</option>

                                    <
    option value="14">14 Slots</option>

                                    <
    option value="16">16 Slots</option>

                                    <
    option value="18">18 Slots</option>

                                    <
    option value="20">20 Slots</option>

                                    <
    option value="22">22 Slots</option>

                                    <
    option value="24">24 Slots</option>

                                    <
    option value="26">26 Slots</option>

                                    <
    option value="32">32 Slots</option>

     

     

                        </
    select></td></tr><tr><td>

     

    [
    b]Tipo Server[/b]</td><td>

            <
    select name="type" id="type" onChange="changePrice();" style="width:175px">

                                     <
    option value="2">Pubblico</option>

                                    <
    option value="1">Privato</option>

                        </
    select></td></tr><tr><td>

     

    [
    b]Tag GameHost.it[/b]</td><td>

    <
    select id="tag" name="tag" onChange="changePrice();" style="width:175px">

    <
    option value="0">Prima il nome</option>

    <
    option value="1">Dopo il nome</option>

    <
    option value="3">No</option>

    </
    select>

    </
    td></tr><tr><td>

    [
    b]Durata[/b]</td><td>

    <
    select id="period" name="period" onChange="changePrice();" style="width:175px">

                            

                                    <
    option value="270">Trimestrale (-10%)</option>

                                    <
    option value="510">Semestrale (-15%)</option>

                                    <
    option value="900">Annuale (-25%)</option>

                        </
    select>

    </
    td></tr><tr><td>

    [
    b]Location[/b]</td><td>

            <
    select id="locationserver" name="location" onChange="changePrice();" style="width:175px">

                            <
    option value="mln">Milano</option>

                            <
    option value="prg">Parigi</option>

                        </
    select>

    </
    td></tr></table>



    </
    div>


    <
    center>[b]Prezzo  &euro;[/b]

    <
    input name="totalprice" id="totalprice" type="text" style="background: #FFF;" onFocus="this.blur()" value="16" size=10>      



    <
    input name="invio" style="background-color: #FFF; border: Solid 1px #DDD; font-weight: bold;" type="submit" style="background: #FFF;" value="Aggiungi al carrello" size=10>

     </
    center>



    </
    form>

    <
    script language="JavaScript" type="text/JavaScript">

    function 
    roundNumber(numdec) {

            var 
    result Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);

            return 
    result;

     

    }

    function 
    changePrice()

    {

     

    var 
    totalt document.getElementById("totalprice");

    var 
    slot document.getElementById("player");

    var 
    period document.getElementById("period");

    var 
    type document.getElementById("type");

    var 
    tag document.getElementById("tag");

    slot parseFloat(slot[slot.selectedIndex].value);

    type parseFloat(type[type.selectedIndex].value);

    tag parseFloat(tag[tag.selectedIndex].value);

    period=parseFloat(period[period.selectedIndex].value);

    totalt.value=  roundNumber((slot+type+tag)/100*period,2);

    }

    </script>

    </div> 
    Dovrei mettere un prezzo a slot a seconda del gioco che viene selezionato e metterlo nel totalt.value

    Sai come posso fare?

  6. #6
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    Originariamente inviato da mario19xx
    Posso chiederti anche un'altra cosa.
    puoi farlo in una nuova discussione, che vedo hai gia' aperto!

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.