0

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

1
  • Unless that loop only executes once, you're going to be outputting MULTIPLE identical copies of the same JS - you're not insert any PHP variables in the JS, so you'll be adding a new select/option set each time the loop runs. Commented Nov 10, 2011 at 15:02

1 Answer 1

3
select.onchange = function(){ ciao( "whatever" ) };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.