0

I'm trying to make a search for an XML tree. This search is made through a specific node attribute. Although it already works, I want to make this search case insensitive, so it can return every single node with that attribute value.

With that in mind, I decided to make a simple function that receives an XML and the input value (texto parameter is that input). But I can't seem to make it work, I know the problem is in the match function, if I create a value like var technician = "technician " and put that value in the match, it works, but I want to make it dynamic, since the values should be coming from an input. How can I do it?

function caseinsensitve(xml, texto) {
    $(xml).find('profissao').filter(function () {
        return ($(this).attr('codigo') || '').match(/texto/i);
    });
}
Gary Sheppard
  • 3,877
  • 3
  • 20
  • 33
Aires Menezes
  • 75
  • 1
  • 13
  • 1
    Possible duplicate of [How do you use a variable in a regular expression?](https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression) – Andreas Jan 03 '18 at 17:08
  • Have you tried to convert both values to upper or lowercase while doing comparision? – Sasu Jan 03 '18 at 17:40

1 Answers1

0

I want to thank Bojangles for giving me the idea to solve this. The answer he gave for another question is in here.

 var texto = $("#pesq_profissao").val();   
 var resultado;
var valor = $(xml).find('profissao').filter(function() {
            return ($(this).attr('codigo') || '').toLowerCase().indexOf(texto.toLowerCase()) > -1;
            });

        resultado = valor;
Aires Menezes
  • 75
  • 1
  • 13