-1
//INSERIR
function move_patr_seri(Origem, Destino)
{
var w_Cont_Qtde = 0;
var w_Qtde_Peri = 4;
var v_patr = new Array();
var w_valor = Origem.value;
var w_tipo;
w_tipo = "S";
if(Origem.name == "tx_patr")
{
w_tipo = "P";
}
if (w_Cont_Qtde <= w_Qtde_Peri - 1)
{
if ((v_patr.indexOf(w_tipo+w_valor) == -1) && (w_valor != ""))
{
var opt = document.createElement("option");
opt.text = w_valor ;
opt.value = w_valor ;
Destino.options.add(opt);
//Cria o Vetor
v_patr[w_Cont_Qtde] = w_tipo + w_valor;
w_Cont_Qtde = w_Cont_Qtde + 1;
if (Origem.name == "tx_patr"){ document.forms['sai_frm_incl_patr_seri'].tx_patr.focus();}
else { document.forms['sai_frm_incl_patr_seri'].tx_seri.focus(); }
return true;
}
else
{
alert("Patrimônio OU Serial já existe OU não é válido!");
return true;
}
}
else
if(w_ver == 1){
alert("Quantidade atingida!");
if(confirm("Deseja inserir a mesma quantidade para ambos?") == true)
{
w_cont = w_Qtde_Peri;
w_ver = 0;
w_Qtde_Peri = w_Qtde_Peri + w_Qtde_Peri;
return true;
}
}
else
alert("Quantidade informada ja Incluida !!!");
return true;
}
function tira(Destino)
{
var w_letra;
var w_tira;
w_letra = "S";
if (Destino.name == "cb_Patr"){
w_letra = "P";
}
var i;
for(i = 0; i < Destino.options.length; i++)
{
if (Destino.options[i].selected && Destino.options[i].value != "")
{
w_tira = w_letra+Destino.options[i].value;
v_patr.splice(v_patr.indexOf(w_tira), 1);
w_Cont_Qtde = w_Cont_Qtde - 1;
Destino.remove(Destino.selectedIndex);
}
}
}
<form name="sai_frm_incl_patr_seri" method="post" >
<body>
<table>
<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>
</tr>
</table><br>
</body>
</form>
I have a snippet of code that the user inserts data into a box and can remove if they wish. So that was the include part. Now I’m in the "alteration" which is basically the same code, where I only populate the box with the data that the user typed and he sees if he wants to remove or insert more data. But, the function is not taking the data that is showing. Code:
HTML
<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">
<?
$w_querybusca="$w_select;";
$w_queryresultado=f_class_conecta_bd($w_querybusca);
while($w_registro = pg_fetch_object($w_queryresultado))
{
print('<option value="'.$w_registro->tx_num_patr.'">'.trim($w_registro->tx_num_patr).'</option>'."\n");
}
?>
</select>
<br>
<input type="button" align="center" valign="middle" onClick="tira(this.form.cb_Patr)" value="<<">
<br>
</td>
In this stretch I have the box and buttons to include and remove in the box!
JS
//RETIRAR
function tira(Destino)
{
var w_letra;
w_letra = "S";
if (Destino.name == "cb_Patr"){
w_letra = "P";
}
var i;
for(i = 0; i < Destino.options.length; i++)
{
if (Destino.options[i].selected && Destino.options[i].value != "")
{
w_tira = w_letra+Destino.options[i].value;
v_patr.splice(v_patr.indexOf(w_tira), 1);
w_Cont_Qtde = w_Cont_Qtde - 1;
Destino.remove(Destino.selectedIndex.value);
}
}
}
That’s the função
which takes data from box
, where v_patr
contains the data that he informed in the inclusion and w_letter is added in front of the value to thus remove from v_patr also (because in it is added the letters before).
The problem lies in v_patr.splice(v_patr.indexOf(w_tira), 1);
, where I’m adding the data to it like this:
<?php
$w_select ="SELECT * FROM public.sai_cad_patr_seri WHERE
sai_cad_patr_seri.fk_seq_cara_peri = '$arr_w_param[17]'";
$w_querybusc = "$w_select;";
$w_queryresult=f_class_conecta_bd($w_querybusc);
$index = 0;
$patr = array();
$seri = array();
while($w_registro = pg_fetch_object($w_queryresult))
{
$patr[$index] = "P".trim($w_registro->tx_num_patr);
$seri[$index] = "S".trim($w_registro->tx_num_seri);
$index++;
}
$string_patr = implode(",", $patr);
$string_seri = implode(",", $seri);
print("<SCRIPT language=javascript>
v_patr = new Array (2);
v_patr = string_patr+','+ string_seri;
</SCRIPT>");
?>
You can put an example of how HTML looks in the browser?
– Sergio
And by the way, what do you want with
Destino.remove(Destino.selectedIndex);
?– Sergio
@Sergio, with this excerpt I intend to remove the selected value from the combo!
– Felipe
Please note that this example does not help you: http://answall.com/questions/35184/copiar-um-option-select-multiple-para-outra-select-multiple-c
– Diego Filipe Pedro Santos
@Diegosantos I appreciate the example, but it doesn’t fit into the "company criteria", they kind of don’t like Jquery!
– Felipe
@Sergio, about the function
Destino.remove(Destino.selectedIndex.value);
he takes the value of the combo and removes it from her! But the return she is giving is undefinid! What would be?– Felipe
You could put your code in shape Executable here in SO.pt or on Jsfiddle so we can work on it?
– KaduAmaral
Of course @Kaduamaral
– Felipe
@Kaduamaral’s executable does not work because it takes php variables and uses them together with JS!
– Felipe
So @Felipe, just run it on your project and copy the generated source code...
– KaduAmaral
ready @Kaduamaral edited to work according to how I’m doing!
– Felipe
And as you can see he doesn’t take the data!
– Felipe