Create associative array to store data structure

0

My question is based on: "I have a small piece of code where the user types how many colleges there are in the area, how many rooms there are, how many subjects and how many students. and according to the number of students a name is included for them Ex Descriptive:

  • Number of students: 16;
  • College Level: 2;
  • Subject matter: 2;
  • Room Qty: 2;

So I have to add a name for these students to the array (associative) for these students and then issue a search showing, for example, which students are in room 0 (for the array ); Also I'm not sure if it should be an associative, as I'm saving the other fields in variables.

Code so far:

function f_veri_conteudo()
{

    if(document.forms["cad_op"].tx_cole.value == ""){
        alert("Informe a quantidade de colegios!");
        return false;
    }
    else{

        w_cole = document.forms["cad_op"].tx_cole.value;

    }

    if(document.forms["cad_op"].tx_sala.value == ""){
        alert("Informe a quantidade de salas!");
        return false;
    }
    else{
        w_sala = document.forms["cad_op"].tx_sala.value;
    }   

    if(document.forms["cad_op"].tx_mate.value == ""){
        alert("Informe a quantidade de materias!");
        return false;
    }
    else{
        w_mate = document.forms["cad_op"].tx_mate.value;
    }

    if(document.forms["cad_op"].tx_alun.value == ""){
        alert("Informe a quantidade de alunos!");
        return false;
    }   

    var w_min_cole = parseInt(w_sala)+ parseInt(w_sala);
    w_min_cole = w_min_cole * w_cole;
    w_min_cole = w_min_cole * w_mate;

    if(document.forms["cad_op"].tx_alun.value < w_min_cole)
    {
        alert("informe no minimo "+w_min_cole+" alunos!");
        return false;
    }
    else{
        w_alun = document.forms["cad_op"].tx_alun.value;
    }

    alert("adicionado com sucesso!");
  }

HTML:

<html>
<body>
    <form name="cad_op">
    <tr>
        <td>
            <font face="arial" size="-1">Colegio:</font>
            <input type="text" id="id_cole" name="tx_cole" size="5" maxlength="3" value="">
        </td>
    </tr>
    <tr>
        <td>
            <font face="arial" size="-1">Salas:</font>
            <input type="text" id="id_sala" name="tx_sala" size="5" maxlength="3" value="">
        </td>
    </tr>
    <tr>
        <td>
            <font face="arial" size="-1">Materia:</font>
            <input type="text" id="id_mate" name="tx_mate" size="5" maxlength="3" value="">
        </td>
    </tr>   
    <tr>
        <td>
            <font face="arial" size="-1">Alunos:</font>
            <input type="text" id="id_alun" name="tx_alun" size="5" maxlength="3" value="">
        </td>
    </tr>
    <tr>
        <td>
            <button type="button" name="btn_mate" style="width:55" onclick="f_veri_conteudo();">Enviar</button>         
        </td>
    </tr>
    </form>
</body>
</html> 

As an example I would have the array:

$array_pessoa['S'] = $array_sala;
$array_pessoa['C'] = $array_cole;
$array_pessoa['M'] = $array_mate;

And I wanted to report as an example in position 0 of each of the indexes of $array_pessoa a name and so on. Thereafter show which person is in such matter or such room (according to position).

    
asked by anonymous 11.11.2014 / 12:28

0 answers