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

Asked

Viewed 51 times

0

I have a classic Asp page 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 have 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 option selected.

The number of combos is not automatic. It is possible to check all combos in javascript before giving Submit on the page?

Combo names follow a pattern "status_previous_<%=counter %>" starting at 0.

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;
}
  • I ended up making several modifications, but this code was the basis for EVERYTHING!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.