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

    form: come fare apparire campi imput con radiobutton

    Ciao, premesso che ho consultato il forum e non ho trovato una risposta precisa, vorrei sapere come posso attraverso due radio button rendere visibile un campo input determinato.
    In sostanza: ho due radio button, se spunto la prima compare un campo, se clicco l'altra ne compare un altro, spero di essere stato chiaro,

    Nicola

  2. #2
    up

    Al limite portreste indicarmi qualche guida sui form e le interazioni con javascript, mi interessa sapere come aggiungere campi in un form da funzione javascript, finora non sono riuscito a trovare nulla di specifico, grazie a chi mi darà una mano,

    Nicola

  3. #3

    ...............

    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">
    var 
    radioName 'uno';
    var 
    targetName 'target';
    var 
    targetInput 'inputTarget';
    var 
    inputName = new Array('uno','due');
    function 
    getMyRadiotarget )
    {
        var 
    newArray = new Array();
        var 
    myradios document.getElementById(target).getElementsByTagName('input');
        for(var 
    i=0;i<myradios.length;i++)
        {
            if(
    myradios[i].getAttribute('name')==radioName)
            {
                
    newArray[i]=myradios[i];
            }
        }
        return 
    newArray;
    };
    function 
    setEvents()
    {
        var 
    myradios getMyRadio(targetName);
        for(var 
    i=0;i<myradios.length;i++)
        {
            
    addEvent(myradios[i],'click',addInputfalse)
        }
    };
    function 
    getRadioValue()
    {
        var 
    radioValue 0;
        var 
    myradios getMyRadio(targetName);
        for(var 
    i=0;i<myradios.length;i++)
        {
            if(
    myradios[i].checked)
            {
                 var 
    radioValue myradios[i].value;
            }
        }
        return 
    radioValue;
    };
    function 
    addInput()
    {
        var 
    radioValue getRadioValue();
        
    myInput document.createElement('input');
        
    myInput.setAttribute('type','text');
        
    myInput.setAttribute('name',inputName[radioValue-1]);
        if(
    replace document.getElementById(targetInput).firstChild
        {
            
    document.getElementById(targetInput).removeChild(replace);
        }
        
    document.getElementById(targetInput).appendChild(myInput);
        
    //alert(document.getElementById(targetInput).firstChild.getAttribute('name'));
    }
    function 
    addEvent(elmevTypefnuseCapture)
    {
        if (
    elm.addEventListener
        {
            
    elm.addEventListener(evTypefnuseCapture);
            return 
    true;
        } 
        else if (
    elm.attachEvent
        {
            var 
    elm.attachEvent('on' evTypefn);
            return 
    r;
        } 
        else 
        {
                
    elm['on' evType] = fn;
        }
    };

    addEvent(window'load'setEventsfalse)
    </script>

    </head>

    <body>
    <form id="target" name="frm" action="mypage.php" method="post">
    <input name="uno" type="radio" value="1" />
    <input name="uno" type="radio" value="2" />
    <span id="inputTarget"></span>
    </form>
    </body>
    </html> 



    PS.
    Se qc trova il modo di togliere quello span
    ben venga
    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.