Pass data to another input

-2

Good evening, guys, I have a question about which best option is pure php or with javascript remembering that I have to pick up the last data to send to the bank in another. Thisiscurrentlyusingjavascript.butIwanttogothroughphphowcouldIdo?willbelikethislater

//<![CDATA[
window.onload=function(){
var btn = document.getElementById('btn');
btn.addEventListener('click', passar);

function passar() {
    var valorA = document.getElementById("valorA");
    var nome = document.getElementById("nome");
    
    nome.value += (valorA.value + '\n');
};
}//]]> 
<select name="valorA" id="valorA" size="3" multiple>
    <option value="Gezer">Gezer</option>
    <option value="João" selected>João</option>
    <option value="Marcos">Marcos</option>
</select>

<button type="button" id="btn">passar valores</button>Nome:
<textarea id="nome" size="10"></textarea>
    
asked by anonymous 03.11.2015 / 23:53

2 answers

1

Use the Select multiple:

<!DOCTYPE html>
<html lang="pt-br">
  <head>
    <meta charset="utf-8">
    <title>Múltiple Select</title>

    <link href="http://vps.pcminfo.com.br/cacic/bundles/cacicrelatorio/libs/bootstrap-transfer-master/css/bootstrap.css" rel="stylesheet">
    <link href="http://vps.pcminfo.com.br/cacic/bundles/cacicrelatorio/libs/bootstrap-transfer-master/css/bootstrap-transfer.css" rel="stylesheet">
  </head>

  <body>

    <h1>Passar Valores</h1>
    <div id="caixa_listagem" style="width:400px">
    </div>

    <script src="http://vps.pcminfo.com.br/cacic/bundles/cacicrelatorio/libs/bootstrap-transfer-master/js/jquery.js"></script><scriptsrc="http://vps.pcminfo.com.br/cacic/bundles/cacicrelatorio/libs/bootstrap-transfer-master/js/bootstrap-transfer.js"></script>
    <script>
        $(function() {
            var t = $('#caixa_listagem').bootstrapTransfer(
                {'target_id': 'multi-select-input',
                 'height': '15em',
                 'hilite_selection': true});

            t.populate([
                {value:"1", content:"Gezer"},
                {value:"2", content:"João"},
                {value:"3", content:"Marcos"},
            ]);
             //2 é total de selecionados, e 3 é o total de elementos
            //t.set_values(["2", "3"]);
            console.log(t.get_values());
               enviarDados(t.get_values());
        });

       function enviarDados(dataList) {
           $.post('enviar_dados.php', {dados:dataList}, function(data) {
            //enviar os dados para o php via ajax
           });
       }
    </script>
  </body>
</html>

To send the data, you can use the jquery post method:

Here's a demo . >.

Here you can download the library .

    
04.11.2015 / 12:30
0

I just had to create this scheme and I increased the script by adding another function only with the name of the selected file so that it is possible to capture it. and created a for in php to capture the rs list

Follow the code to help people.

<script language="JavaScript">
function move(MenuOrigem, MenuDestino){
    var arrMenuOrigem = new Array();
    var arrMenuDestino = new Array();
    var arrLookup = new Array();
    var i;
    for (i = 0; i < MenuDestino.options.length; i++){
        arrLookup[MenuDestino.options[i].text] = MenuDestino.options[i].value;
        arrMenuDestino[i] = MenuDestino.options[i].text;
    }
    var fLength = 0;
    var tLength = arrMenuDestino.length;
    for(i = 0; i < MenuOrigem.options.length; i++){
        arrLookup[MenuOrigem.options[i].text] = MenuOrigem.options[i].value;
        if (MenuOrigem.options[i].selected && MenuOrigem.options[i].value != ""){
            arrMenuDestino[tLength] = MenuOrigem.options[i].text;
            tLength++;
        }
        else{
            arrMenuOrigem[fLength] = MenuOrigem.options[i].text;
            fLength++;
        }
    }
    arrMenuOrigem.sort();
    arrMenuDestino.sort();
    MenuOrigem.length = 0;
    MenuDestino.length = 0;
    var c;
    for(c = 0; c < arrMenuOrigem.length; c++){
        var no = new Option();
        no.value = arrLookup[arrMenuOrigem[c]];
        no.text = arrMenuOrigem[c];
        MenuOrigem[c] = no;
    }
    for(c = 0; c < arrMenuDestino.length; c++){
        var no = new Option();
        no.value = arrLookup[arrMenuDestino[c]];
        no.text = arrMenuDestino[c];
        MenuDestino[c] = no;
   }
   
}
function selecionatudo(){
	    var selecionados = document.getElementById('list2');
		for(i=0; i<=selecionados.length-1; i++){
			  selecionados.options[i].selected = true;
		
		}
	}
</script>
<html>
   <head>
        <title>Movendo itens de um select para o outro</title>
   </head>
   <body>
    <?php
        $list = $_POST['list2'];
        $count = count($list);
        
        for($i=0; $i<$count;$i++){
            $item = $list[$i];	
            echo $item. '<br/>';
        }
    ?>
    <table>
        <form name="listbox"  action="?go=cadastrar" method="post">
            <tr>
                <td height="194">
                    <select multiple size="10"  id="usuario" name="list1" style="width:150">
                        <option value="teste1"> teste1 </option>
                        <option value="teste2"> teste2 </option>
                        <option value="teste3"> teste3 </option>
                    </select>
                </td>
                <td align="center" valign="middle">
                    <input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<">
                    <input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>">
                </td>
                <td>
                    <select  size="10" name="list2[]" id="list2"  multiple="multiple" style="width:150"></select>
                    <td align="center" valign="middle">
                        <input type="submit" name="Enviar" value="Enviar"  onClick="selecionatudo();">
                    </td>
                </td> 
            </tr>
        </form>
    </table>
   </body>
</html>
    
04.11.2015 / 02:36