Pass data to another input

Asked

Viewed 1,124 times

-2

good evening guys I’m with a doubt which best pure php option or with javascript remembering that I have to take the past data to send to the bank in another. inserir a descrição da imagem aqui It is currently using java script. but I want to go by php how could I do it? it’ll be like this after inserir a descrição da imagem aqui

//<![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>

  • 1

    If you are going to pass via php, you will have to click on the "pass values" button, include the selected items in the database and then load the information in the inputs and update, using ajax you can do this without submitting the whole page.

  • vi da para fazer usando o Exploder e inplode separating by commas what do you think? Ai think that Listbox would go separately to the bank?

  • Yes, use the implode(or Join) functions and explode, as you differentiate the values of the right and left in the database ?

  • You don’t asked that yesterday? If the answer did not answer your question there, why marked as resolved?

  • because it was only javascript and here I want php I’m already understanding rs I saw that I would have to capitulate the data that are going par to listbox 2 and for that I would have to increase the script by creating another Function. but only this is with php. this only php.

  • 2

    Do you want to pass the values from select to the textarea with PHP? Php runs on the server, no? I think that the only way would be to make a request for the server process the php code and generate the html you will use in the textarea. It seems impracticable a request just for that, but anyway...

  • You can send the data via ajax in JSON, every click to PHP.

Show 2 more comments

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>
    <script src="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 demonstration.

Here you can download the library.

  • Damn how much information we thank you very much Thank you very much Will help me a lot.

0

look I only had to create this scheme I increased the script by putting one more Function so that with the name of selecting everything being so possible to capture. and created a for in php to capture the list rs

follow the code to help the crowd.

<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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.