1
Opa,
I believe it should be simple, but, I did not get a perfect functioning.
I have a function that when clicked should check the value contained in an input text, the values are separated by a /
and are whole. I need that when this function is executed, it sends an integer value and check that this value is contained in the input, if it is, you should remove it, if not, you should include it, I tried it like this:
var opcoes_selecionadas = document.getElementById("options_add_input").value;
if(opcoes_selecionadas.search("/"+opcao_id+"/")){
alert('string encontrada');
}
else
{
opcoes_selecionadas = opcoes_selecionadas + "/" + opcao_id;
document.getElementById("options_add_input").value = opcoes_selecionadas;
}
But it’s not working.
Hey, buddy, sorry for the delay in responding, but when you enter the code, you’re adding normally, but not removing the var
p
is always returning -1, that is, even containing the value in the input is being added.var p = o.indexOf(i);
, i.e., the indexef directly in the input var it returns the position of the value in the input, but, does not remove, just does not add. Could you give me a strength buddy?– sNniffer
Added functional snippet. Maybe your browser version does not support the
indexOf
; check out.– Guill