Comparing two values to perform an if

Asked

Viewed 60 times

0

Good morning, good afternoon and good evening.

I have a code that includes a checkbox and radio listing for my user to select the desired operation, but when marking a radio it should not be able to select any check other than the radio line, but I’m not able to make this block for the other lines, it works only in the first row of my table and I don’t have much knowledge in JS. The function that does not work as imagined is the validationMawb.

   function testaCheck(idMaster) {
    var inputs, i, checados = 0;
    inputs = document.getElementsByTagName("input");
    for (i = 0; i < inputs.length; i++) {
        if (inputs[i].type == "checkbox") {
            if (inputs[i].checked == true) {
                checados++;
                document.getElementsByName('DS_MD' + idMaster).value = idMaster;
                $("#formSelectMAWB").find("#masterDireto").val(idMaster);
            }

        }

    }

    if (checados > 1) {
                uncheckAll(inputs);
                document.getElementsByName('DS_MD' + idMaster).value = null;
                $("#formSelectMAWB").find("#masterDireto").val(null);
            }
};  

function uncheckAll(inputItems){
    alert("MAWB não selecionado ou MAWB diferente do Direto. Favor refazer a seleção");
    for (i = 0; i < inputItems.length; i++) {
        inputItems[i].checked = false;
    }
}

function validaMawb(){

var d = document.getElementsByName('DS_MD' + idMaster).value();
var m = document.getElementById('idMAWB').value;

if(d.value !== m.value){
    uncheckAll(inputs);
    document.getElementsByName('DS_MD' + idMaster).value = null;
    $("#formSelectMAWB").find("#masterDireto").val(null);   

}}

            <div class="linhaLista">
            <div class="campoLista TamanhoCampoLista7" title="">
                <div class="input-control span1 floatForm-left"> 
                    <label class="input-control radio">
                        <input type="radio" name="idMAWB" id="idMAWB" value="<%=ID_CD_MAWB%>" onClick="selecionaMAWB(this.value);">
                        <span class="helper"><%=DS_MAWB%></span>
                    </label>    

                    <label for="DS_MD<%=ID_CD_MAWB%>">
                    <input type="checkbox" name="DS_MD<%=ID_CD_MAWB%>" id="masterDireto<%=ID_CD_MAWB%>" onClick="testaCheck(<%=ID_CD_MAWB%>);validaMawb();">
                     <span class="helper"> Master Direto </span>
                     </label>
                </div>
            </div> 
  • 1

    You can’t repeat id’s, otherwise you’ll always get the first one.

  • So where I have the script from validaMawb I would have to use another means to call the comparison variables?

  • Which div is repeating?

  • To <div class="input-control span1 floatForm-left"> which is the third div always repeats itself by being part of the listing construction.

  • I would have to use another medium. But your code is all wrong. You have to redo it almost all, as I see it.

  • I get it Sam, if you can give me a direction where to start or some place to study better thank you, I’m starting in js

Show 1 more comment

1 answer

0


After redoing the code, I got what I needed with this topic, in case someone needs to follow below the functional code.

function testaCheck(idMaster) {
    var inputs, i, checados = 0;
    var idmasterOption = $("#formSelectMAWB").find("#idMAWB").val();
    inputs = document.getElementsByTagName("input");
    for (i = 0; i < inputs.length; i++) {
        if (inputs[i].type == "checkbox") {
            if (inputs[i].checked == true) {
                if (idMaster != idmasterOption) {
                     uncheckAll(inputs);                    
                    $("#formSelectMAWB").find("#masterDireto").val(null);
                    $("#formSelectMAWB").find("#idMAWB").val(null);
                        if ( valor != null){
                            $("#formSelectMAWB").find("#idMAWB").val(null);
                        }
                    }
                else {
                    document.getElementsByName('DS_MD' + idMaster).value = idMaster;
                    $("#formSelectMAWB").find("#masterDireto").val(idMaster);
                    }
                    checados++;
            }           
        }
    }   
    if (checados > 1) {
                uncheckAll(inputs);
                $("#formSelectMAWB").find("#masterDireto").val(null);
                $("#formSelectMAWB").find("#idMAWB").val(null);             
            }
};  

function uncheckAll(inputItems){
    alert("MAWB não selecionado ou MAWB diferente do Direto. Favor refazer a seleção");
    for (i = 0; i < inputItems.length; i++) {
        inputItems[i].checked = false;
    }
}

Browser other questions tagged

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