Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it L'avatar di jerico
    Registrato dal
    Nov 2002
    Messaggi
    55

    novizio di programmazione

    Ciao a tutti come posso recuperare un valore da una select e mostrarlo in una finestra alert con un evento OnChange. Ho provato così ma sono sicuramante fuori strada:

    function mostra() {
    var valore = document.productsearch.categoria.options[].text
    for (var i=0; i< productsearch.categorie.lenght; i++){
    if(categoria[i] == valore) {
    break
    }
    }
    alert(valore)
    }
    Mi potete correggere per favore?

  2. #2
    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 type="text/javascript"
    function 
    clear_selectedindex(selEl){
        var     
    opts    selEl.options
                for (var 
    i=0;i<opts.length;i++) {
                    
    alert(  "Text: "+opts[i].text
                            
    "\r\nValue: "+opts[i].value
                            
    "\r\nSelected: "+(opts[i].selected?"yes":"no") ); 
    }
    }

    </script>

    </head>

    <body>
    <select id="sel"  onChange="clear_selectedindex(this);"> 
            <option value="a">Aquarion</option> 
            <option value="b">Broken</option> 
            <option value="c">3. Celiane</option> 
    </select> 


    </body>
    </html> 


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3
    Utente di HTML.it L'avatar di jerico
    Registrato dal
    Nov 2002
    Messaggi
    55
    Grazie whisher ma che significato ha l'argomento (selEl) ?

  4. #4
    Originariamente inviato da jerico
    Grazie whisher ma che significato ha l'argomento (selEl) ?

    E' l'oggetto select.

    onChange="clear_selectedindex(this);"

    all'onChange appunto passi this che è un riferimento
    alla select.

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

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.