Check if a specific item is selected in one of the combos on the page

0

I have a page in asp classic with several combos and all with different names and a button that saves all selected values. I need to check in javascript if any of these combos has the "Canceled" option selected and give a confirmation message saying that one of the combos has this option selected. You need to show this confirmation for all combos with this selected option.

The number of combos is not automatic. Is it possible to check all the combos in the javascript before submitting the page?

The names of the combos follow a pattern "status_anterior_

asked by anonymous 20.09.2016 / 20:12

1 answer

1

You can do this using jQuery, as follows:

function ValidarAcao() {
    var algumItemCancelado = false;

    $('select').each(function(i, e){
        if ($(e).attr("id").indexOf("status_anterior_") > -1 && $(e).val() == "Cancelado") {
            algumItemCancelado = true;
        }
    });

    if (algumItemCancelado){
        return confirm("Existe um ou mais itens com a opção 'cancelado' selecionados. Deseja continuar?");
    }

    return true;
}
    
20.09.2016 / 20:35