Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Indirizzare evento onchange su select dinamica

    Ciao ragazzi,

    ho creato dinamicamente una tabella con delle input e delle select.
    Ora devo indirizzare la funzione calcola all'evento onchange della select, ma come l'ho scritta non funziona.
    Forse perche' richiama una funzione esterna alla funzione che mi crea le select e le input.
    Non so. C'è qualcuno che mi puo' aiutare??Allego codice

    codice:
    <script type="text/javascript"> 
     
    var riga=0; 
    /* funzione Add */ 
     
    function Add(id_table) 
        { 
        riga=riga+1; 
        var table = document.getElementById(id_table); 
        var tbody = table.getElementsByTagName('tbody')[0];  
        var tr = document.createElement("tr"); 
        for(var i=0; i<7; i++) 
            { 
            if(i!=4) 
                { 
                var td = document.createElement('td'); 
                var tx = document.createElement("input"); 
                if(i>4) 
                    { 
                    tx.type="text"; 
                    tx.readOnly="true"; 
                    tx.id="id"+i+riga; 
                    tx.value=0;  
                    } 
                else     
                    { 
                    tx.type="text"; 
                    tx.id="id"+i+riga; 
                    tx.value=0; 
                    tx.onkeyup="char_consentiti(this)";    //NON FUNZIONA !!
                    } 
                td.appendChild(tx); 
                tr.appendChild(td); 
                } 
            else 
                {     
                    td = document.createElement('td'); 
                    tx = document.createElement("select"); 
                    tx.options[tx.length] = new Option('abete kvh'); 
                    tx.options[tx.length] = new Option('abete lamellare'); 
                    td.appendChild(tx); 
                    tr.appendChild(td); 
                    tx.id="id"+i+riga; 
                    tx.onchange="calcola()";        //NON FUNZIONA!!
                }     
            } 
        tbody.appendChild(tr); 
        } 
     
     
    /* funzione calcola */ 
     
    function calcola() 
    { 
        selIdx = document.forms[0].materiale.selectedIndex; 
        switch (selIdx) 
            {    case 0:        { price=325; 
                          break; 
                        } 
                case 1:        { price=396; 
                        break; 
                        } 
            }
     }
    Sapreste aiutarmi??
    Grazie

  2. #2
    tx.onkeyup=function() {char_consentiti(this)};
    tx.onchange=function() {calcola()};


    HO RISOLTO, GRAZIE!!

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.