Block insertion in box

Asked

Viewed 47 times

0

In the code I create two box, one patrimonio and another serial:

<table border="0" align="center" height="100">
    <tr>
        <td>   
            <font face="arial" align="center" valign="middle" color="blue" size="-1">PATRIMÔNIO</font><br>
            <input type="text" name="tx_patr" id="id_patr" maxlength="12" size="12" style="font-size:11; color:Black;" onkeypress="return SomenteNumero(event);" onkeyup="Mascara(this,Patri);" value="">
            <input type="button" onClick="move_patr_seri(this.form.tx_patr,this.form.cb_Patr);limpa_patr();" value=">>">
            <br>
            <select multiple size="7" name="cb_Patr" style="width:300"></select>
            <br>
            <input type="button" align="center" valign="middle" onClick="tira(this.form.cb_Patr)" value="<<">
            <br>
        </td>
        <td align="center" valign="middle" width="15%">
        </td>
        <td>  
            <font face="arial" align="center" valign="middle" color="blue" size="-1">SERIAL</font><br>
            <input type="text" name="tx_seri" id="id_seri"  maxlength="15" size="15" style="font-size:11; color:Black;" onblur="evento(this)"  value="">
            <input type="button"  onClick="move_patr_seri(this.form.tx_seri,this.form.cb_Seri);limpa_seri();" value=">>">
            <br>
            <select multiple size="7" name="cb_Seri" style="width:300"></select>
            <br>
            <input type="button" align="center" valign="middle" onClick="tira(this.form.cb_Seri)" value="<<">
            <br>
        </td>
    </tr>
</table>  

I want to block a box insertion if an informed amount (coming from a previous program) is reached. For example: "Informed quantity = 3, so the user can only enter 3 assets and if he wants 3 serials. If you want to enter 4 assets or serial it must be blocked."!

EXAMPLE IN JSF: Example of the box and the insertion Javascript

Obs* The variables that are in JSF

var w_Qtde_Peri = 3; -> Quantidade informada
var w_Cont_Qtde = 0;
     var  w_ver = 1;
     var v_patr = new Array (w_Qtde_Peri);  

are of PHP, so it will not include in the box!

1 answer

1

I managed to come up with an answer to my problem!

In case to block, just need to add this snippet:

 if((Destino.name == "cb_Seri") && (Destino.options.length == w_cont))
    { return false;} 
 if((Destino.name == "cb_Patr") && (Destino.options.length == w_cont))
    { return false;} 

Where w_cont receives the informed quantity, thus not allowing the user to enter more than the total quantity in the box!

Browser other questions tagged

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