pindol
pindol

Reputation: 2110

Add event on HTML select using javascript

I need to add a function on onchange event of a html select using javascript. I need to do it with javascript because if i don't use it IE doesn't work. I write this code:

<script>
    <?php foreach($this->segnali as $segnale) : ?>

        var div = document.getElementById("segnali");
        var select = document.createElement("select");
        select.onchange = ciao;
        div.appendChild(select);

        var opt = document.createElement('option');
        opt.setAttribute("value", "1");     
        opt.setAttribute("id", "input");    
        opt.text = "Settimanale"; 
        select.add(opt);
        var opt = document.createElement('option');
        opt.setAttribute("value", "2");     
        opt.setAttribute("id", "input");    
        opt.text = "Mensile"; 
        select.add(opt);

<?php endforeach; ?>

function ciao() {
    alert("ciao");
}
</script>

This work but i need to pass a parameter to ciao function. How can i do that? It must works with FF, Chrome and IE. Thanks, Mattia

Upvotes: 0

Views: 3371

Answers (1)

epascarello
epascarello

Reputation: 207547

select.onchange = function(){ ciao( "whatever" ) };

Upvotes: 3

Related Questions