How to treat (String) value with jquery?

1

I have a field that when populated it makes several triggers, beauty up there, it's okay with the code below.

$("#teste").change(function () {
    var valor = $(this).val();
    $("#nome").val(valor);
    $("#idade").val(valor);
});

The problem is that my field comes with an example information, maicon/29 , name and age how do I get it in jQuery to get all the information up to the bar and also get all information after the bar, how do I do this? What if I have another bar, how to treat it?

    
asked by anonymous 22.06.2016 / 22:41

1 answer

5

Try to use split("/") :

$("#teste").change(function () {
    var valor = this.value.split("/");
    $("#nome").val(valor[0]);
    $("#idade").val(valor[1]);
});
    
22.06.2016 / 22:54