move text to a box

Asked

Viewed 364 times

2

Well, I want to pass on the values I put on <input> to the "box" and also have the option to take it.

Example:

<table border="1" align="center" height="180">
    <tr>
        <td>    <font face="arial" align="center" valign="middle" color="blue" size="-1">PATRIMÔNIO</font></br>
            <input type="text" name="tx_MenuOrigem" maxlength="16" size="16" style="font-size:11; color:Black;" onkeypress="return SomenteNumero(event);" value="">
            <input type="button" onClick="move(this.form.tx_MenuOrigem,this.form.cb_MenuDestino)" value=">>">
            <br>
            <select multiple size="9" name="cb_MenuDestino" style="width:300"></select>
            <br>
            <input type="button" align="center" valign="middle" onClick="tira(this.form.cb_MenuDestino)" value="<<">
            <br>
        </td>
        <td align="center" valign="middle" width="15%">
            <br>
        </td>
        <td>    <font face="arial" align="center" valign="middle" color="blue" size="-1">SERIAL</font>

            </br>
            <input type="text" name="cb_MenuOrigem2" maxlength="16" size="16" style="font-size:11; color:Black;" onkeypress="return SomenteNumero(event);" value="">
            <input type="button" onClick="move(this.form.cb_MenuOrigem2,this.form.cb_MenuDestino2)" value=">>">
            <br>
            <select multiple size="9" name="cb_MenuDestino2" id="cb_MenuDestino2" style="width:230"></select>
            <br>
            <input type="button" align="center" valign="middle" onClick="tira(this.form.cb_MenuDestino)" value="<<">
            <br>
        </td>
    </tr>
</table>

Example in JSF: Example code

In JSF I left an example with a function, more or less what it should do. In the case of function in JSF, the user selects the option to popular the other box).

  • has to be in pure javascript? if using jquery makes the work much easier and works in any browser...

  • @Jader, it can be in jquery, as long as you solve my problem if possible!

  • It’s not difficult just with javascript... http://www.johnwbartlett.com/cf_tipsntricks/index.cfm?TopicID=86

2 answers

2


Here is a brief example in jquery: (just include the necessary conditions and checks)

jquery:

$('.botao_add').click(function(){
    $(this).parent().children('select').append($('<option>', {
    value: $(this).parent().children('input:first').val(),
    text: $(this).parent().children('input:first').val()}));
});

$('.botao_del').click(function(){
    $(this).parent().children('select').children('option:selected').each(function() {
        $(this).remove();
    });
});

HTML:

<table border="1" align="center" height="180">
    <tr>
        <td>    <font face="arial" align="center" valign="middle" color="blue" size="-1">PATRIMÔNIO</font></br>
            <input type="text" name="tx_MenuOrigem" maxlength="16" size="16" style="font-size:11; color:Black;" value="">
            <input type="button" class='botao_add' value=">>">
            <br>
            <select multiple size="9" name="cb_MenuDestino" style="width:300"></select>
            <br>
            <input type="button" align="center" valign="middle" class='botao_del' value="<<">
            <br>
        </td>
        <td align="center" valign="middle" width="15%">
            <br>
        </td>
        <td>    <font face="arial" align="center" valign="middle" color="blue" size="-1">SERIAL</font>

            </br>
            <input type="text" name="cb_MenuOrigem2" maxlength="16" size="16" style="font-size:11; color:Black;" value="">
            <input type="button"  class='botao_add' value=">>">
            <br>
            <select multiple size="9" name="cb_MenuDestino2" id="cb_MenuDestino2" style="width:230"></select>
            <br>
            <input type="button" align="center" valign="middle" class='botao_del' value="<<">
            <br>
        </td>
    </tr>
</table>

jsfiddle: http://jsfiddle.net/jaderw/ht5b9xzk/

  • Thank you @Jader, helped me a lot what you gave me !!

1

Source: http://www.johnwbartlett.com/cf_tipsntricks/index.cfm?TopicID=86

Example :

<html>
<head>
<title>Multi-list copy example</title>
<body>
<script language="Javascript">
function SelectMoveRows(SS1,SS2)
{
    var SelID='';
    var SelText='';
    // Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
        if (SS1.options[i].selected == true)
        {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            var newRow = new Option(SelText,SelID);
            SS2.options[SS2.length]=newRow;
            SS1.options[i]=null;
        }
    }
    SelectSort(SS2);
}
function SelectSort(SelList)
{
    var ID='';
    var Text='';
    for (x=0; x < SelList.length - 1; x++)
    {
        for (y=x + 1; y < SelList.length; y++)
        {
            if (SelList[x].text > SelList[y].text)
            {
                // Swap rows
                ID=SelList[x].value;
                Text=SelList[x].text;
                SelList[x].value=SelList[y].value;
                SelList[x].text=SelList[y].text;
                SelList[y].value=ID;
                SelList[y].text=Text;
            }
        }
    }
}
</script>
<form name="Example">
<table border="0" cellpadding="3" cellspacing="0">
    <tr>
        <td>
            <select name="Features" size="9" MULTIPLE>
                <option value="2">Row 2</option>
                <option value="4">Row 4</option>
                <option value="5">Row 5</option>
                <option value="6">Row 6</option>
                <option value="7">Row 7</option>
                <option value="8">Row 8</option>
                <option value="9">Row 9</option>
            </select>
        </td>
        <td align="center" valign="middle">
            <input type="Button" value="Add >>" style="width:100px" onClick="SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)"><br>
            <br>
            <input type="Button" value="<< Remove" style="width:100px" onClick="SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)">
        </td>
        <td>
            <select name="FeatureCodes" size="9" MULTIPLE>
                <option value="1">Row 1</option>
                <option value="3">Row 3</option>
            </select>
        </td>
    </tr>
</table>
</form>

</body>
</html>
  • But in this case it determines the fields in the box itself, and what I need is that the fields that are in the input go into the box, because I will still have a loop of repetition times (but this is another case).

  • well, just do the same as it is done there to add an option, with the value of textbox.. ( and put the value of the textbox empty then obviously )

Browser other questions tagged

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