Visualizzazione dei risultati da 1 a 9 su 9

Discussione: form dinamico

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    855

    form dinamico

    Salve, come si fa a fare un form dinamico nel quale al variare del contenuto di un campo text (valori da 1 a 10) un menù list si aggiorna con campi option diversi?

    Grazie.

  2. #2
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    87
    forse questo è piu da javascript...

    in php nn credo si possa fare nella stessa pagina.. a meno che nn si usa frame..

  3. #3
    solo con php non lo puoi fare, se vuoi una cosina dinamica e bella utilizza AJAX, ci sono dei progetti molto interessanti e ben fatti e sopratutto semplici da capire, come SAJAX oppure se hai voglia ti fai tu una cosa con Protype e il tuo codice PHP
    Zend Framework Italian Forum
    http://www.zfforum.it

  4. #4

    ..........

    Ciao.
    Senza scomodare Ajax puoi recuperare
    i valori di una query e metterli in un array js
    poi ad esempio puoi utilizzare questo codice
    (come tutte le cose si può migliorare )

    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    >
    <
    html>
    <
    head>
    <
    title>MyInput</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="JavaScript" type="text/JavaScript">
    function 
    createInputText()
    {
        var 
    myinput document.createElement("input");
        
    myinput.setAttribute("id""myinput");
        
    myinput.setAttribute("type""text");
        
    document.getElementById("frm").appendChild(myinput);
        
    init();
    }
    function 
    createSelect(myarray)
    {
        if(
    test document.getElementById("myselect")) 
        {
            
    document.getElementById("frm").removeChild(test);
        }
        var 
    myinput document.getElementById("myinput");
        var 
    index myinput.value;
        if(
    index=='' || index==|| index 10)
        {
            
    init();
            return;
        }
        var 
    myselect document.createElement("select");
        
    myselect.setAttribute("id""myselect");
        
    document.getElementById("frm").appendChild(myselect);
        for (
    i=0myarray[index].lengthi++)
        {
            
    document.getElementById("myselect").options[i] = new Option(myarray[index][i],i);
            
        }
    }
    function 
    init()
    {
        var 
    myselect document.createElement("select");
        
    myselect.setAttribute("id""myselect");
        
    document.getElementById("frm").appendChild(myselect);
        
    document.getElementById("myselect").options[0] = new Option("------","0");
    }
    window.onload = function()
    {
        
    // QUESTO LO PUOI FARE CON PHP
        
    var myarray = new Array();
        
    myarray[1] = new Array("uno1","due1","tre1");
        
    myarray[2] = new Array("uno2","due2","tre2");
        
    myarray[3] = new Array("uno3","due3","tre3");
        
    //etc
        
    myarray[10] = new Array("uno10","due10","tre10");
        
    createInputText();
        var 
    myinput document.getElementById("myinput");
        
    myinput.onkeyup = function()
        {
            
    createSelect(myarray);
        }
    }
    </script>

    </head>

    <body>
    <form id="frm" action="mypage.php" method="post" name="frm">

    </form>
    </body>
    </html> 
    Spero che ti possa aiutare.


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

  5. #5
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    855

    e se volessi...

    Ciao Ragazzi...dire che Whisher mi ha dato la soluzione migliore...complimenti davvero!
    Senti una cosa...volendo stampare invece di un menù list una serie di tre, per esempio, radio button o checklist, invece?
    Si può fare?

  6. #6

    .....

    E un caffè
    Penso di sì basta adattare lo script.

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

  7. #7
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    855

    ...

    Oh Whisher, scusa se ti rompo...il problema è che i check-in sono variabili...non so proprio come adattare lo script, magari può essere utile visto che sul sito non c'è nulla in merito...

    Tipo:
    se il campo text è uno, allora stampa due check-in, se tre stampane tre

    Il vantaggio è che sono preimpostati...

    Please...

  8. #8

    ......

    Oh gio-mx quanto rompi
    Here the masterpiece is
    Occhio che c'è il copyright
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    >
    <
    html>
    <
    head>
    <
    title>MyTextBox &copywhisher :)</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="JavaScript" type="text/JavaScript">
    var 
    count 0;
    function 
    createInputText()
    {
        var 
    myinput document.createElement("input");
        
    myinput.setAttribute("id""myinput");
        
    myinput.setAttribute("type""text");
        
    document.getElementById("frm").appendChild(myinput);
        
    }
    function 
    createTextBox()
    {
        var 
    count getCheckBox();
        if(
    count)
        {
            for(
    0countj++)
            {
                
    document.getElementById("frm").removeChild(document.getElementById("mycheckbox" j));
            }
            
        }
        var 
    myinput document.getElementById("myinput");
        var 
    value myinput.value;
        for(
    0valuei++)
        {
            var 
    mytextBox document.createElement("input");
            
    mytextBox.setAttribute("type""checkbox");
            
    mytextBox.setAttribute("id""mycheckbox" i);
            
    mytextBox.setAttribute("value"i);
            
    document.getElementById("frm").appendChild(mytextBox);
        }
        

    }
    function 
    getCheckBox()
    {
        var 
    arrayinput document.getElementsByTagName("input");
        var 
    string "";
        var 
    myTextBox  = new Array();
        if(
    count!=0)
        {
            
    count 0;
        }
        for(
    0arrayinput.lengthi++)
        {
            
    string arrayinput[i].getAttribute("type");
            if(
    string.indexOf("checkbox")!=-1)
            {
                
    count++;
            }
        }
        return 
    count;
    }
    window.onload = function()
    {
        
        
        
    createInputText();
        var 
    myinput document.getElementById("myinput");
        
    myinput.onblur = function()
        {
            
    createTextBox();

        }
    }
    </script>

    </head>

    <body>
    <form id="frm" action="mypage.php" method="post" name="frm">

    </form>
    </body>
    </html> 
    Bugs
    Not bloody likely

    Scherzi a parte se la usi davvero dacci
    una profonda controllata.

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

  9. #9
    Utente di HTML.it
    Registrato dal
    Jan 2004
    Messaggi
    855

    perfetto

    Grazie Wisher, sei un fenomeno...
    P.S. Potresti metterequestoscript negli script della parte javascript...

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.