I want to know how to pass a django for in javascript?

0

This is my code:

{%for obj in empaque %} 
        celdae = {{"obj.celda"}}
        {%enfor%}

        if (document.empaque.celda.value == celdae) {
            alert("La celda ya esta ocupada") document.empaque.celda.focus() return false;}

What I want to do is go through the cycle and compare if the variable you type in the form is the same as one that already exists and if so, then the message will appear and allow me to change the cell number.

There is some way to do it.

    
asked by Angie Lizeth Santiago Piñeros 29.09.2016 в 18:40
source

1 answer

1

You must take that package in your view and bring it to the template as an array, I do not know what you have there, but just in case I leave you this: link

Once cell you can return an array, for example:

celdae = {{ empaque }}

will give you as a result:

celdae = [1, 3, 5, 7, 8]

Once you have it that way, you can check if the entered value exists in that array in this way:

if (celdae.indexOf(document.empaque.celda.value) > -1) {
    alert("La celda ya esta ocupada");
    document.empaque.celda.focus();
    return false;
}
    
answered by 29.09.2016 в 21:20