Create associative array to store data structure

Asked

Viewed 117 times

0

My question is based on: "I have a small code snippet where the user type in how many colleges there are in the region, how many classrooms there are, how many courses and how many students. So far it is easy to define. The problem is the joining of these fields and as the number of students is included a name for them. Ex descriptive:

  • Qty of students : 16;
  • Qty of College : 2;
  • Qty of matter : 2;
  • Qty of room : 2;

So I should add to array (associative) a name for these students and then issue a survey showing for example which students are in class 0 (in the case of array); Also not sure if it should be an associative, because I am 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> 

Just like 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 the position 0 of each of the $array_pessoa a name and so consecutively. Then show which person is in the matter such or such room (depending on the position).

  • 2

    Have you done anything? Try and post here.

  • @bigown as you can see I just did the "body" of the program, I can’t go forward because of adding one student to each thing!

No answers

Browser other questions tagged

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