0

I want to add a row to my table to allow to the user to add data which will be inserted then into the data base. I have imbricated tables (the coed given present just first row to simplify but it’s a long form given as a table).

My first problem is when I add the select to my getElementById it won’t work?

My second problem I don’t know if I can recuperate the fields added by the user and inserted them to my database? I found the example that I have followed in ( Add table row in jQuery )

<html>
  <head>
    <script type="text/javascript">
      function displayResult() {
        document.getElementById("tabsalaire").insertRow(-1).innerHTML = '<td><input name="salaireparstatut4" id="salaireparstatut4" /></td>';
        document.getElementById("tabtitulaire").insertRow(-1).innerHTML = '<td><input name="nbtitulaire4" id="nbtitulaire4" /></td>';
        document.getElementById("tabfemale").insertRow(-1).innerHTML = '<td><input name="nbfemale4" id="nbfemale4" /></td>';
        document.getElementById("tabsommeparstatut").insertRow(-1).innerHTML = '<td><input name="sommeparstatut4" id="sommeparstatut4" /></td>';
        document.getElementById("selectstatus").insertRow(-1).innerHTML = '<td><select name="statutselect4" required> < option value = "" > choisir < /option> < option value = "Professeur" > Professeur < /option> < option value = "Assistant" > Assistant < /option> < /select> < input type = "hidden"
        name = "EnseignementSuperieur"
        value = "EnseignementSuperieur" / > < /td>';
      }
    </script>
  </head>

  <body>
    <form method="post" action="processform.php">
      <table border="1">
        <tr>
          <th>Add</th>
          <th>Salaire annuel</th>
          <th>nombre titulaire</th>
          <th>Nombre femme</th>
          <th>Somme</th>
          <th>Statut</th>
          <th>Type</th>
        </tr>
        <td>
          <table>
            <tr>
              <td>
                <button type="button" onClick="displayResult()">Insert new row</button>
              </td>
            </tr>
          </table>
        </td>
        <td>
          <table id="tabsalaire">
            <tr>
              <td>
                <input name="salaireparstatut1" id="salaireparstatut1" />
              </td>
            </tr>
            <tr>
              <td>
                <input name="salaireparstatut2" id="salaireparstatut2" />
              </td>
            </tr>
            <tr>
              <td>
                <input name="salaireparstatut3" id="salaireparstatut3" />
              </td>
            </tr>
          </table>
        </td>
        <td>
          <table id="tabtitulaire">
            <tr>
              <td>
                <input name="nbtitulaire1" id="nbtitulaire1" />
              </td>
            </tr>
            <tr>
              <td>
                <input name="nbtitulaire2" id="nbtitulaire2" />
              </td>
            </tr>
            <tr>
              <td>
                <input name="nbtitulaire3" id="nbtitulaire3" />
              </td>
            </tr>
          </table>
        </td>
        <td>
          <table id="tabfemale">
            <tr>
              <td>
                <input name="nbfemale1" id="nbfemale1" />
              </td>
            </tr>
            <tr>
              <td>
                <input name="nbfemale2" id="nbfemale2" />
              </td>
            </tr>
            <tr>
              <td>
                <input name="nbfemale3" id="nbfemale3" />
              </td>
            </tr>
          </table>
        </td>
        <td>
          <table id="tabsommeparstatut">
            <tr>
              <td>
                <input name="sommeparstatut1" id="sommeparstatut1" /> </td>
            </tr>
            <tr>
              <td>
                <input name="sommeparstatut2" id="sommeparstatut2" />
              </td>
            </tr>
            <tr>
              <td>
                <input name="sommeparstatut3" id="sommeparstatut3" />
              </td>
            </tr>
          </table>
        </td>
        <td>
          <table id="selectstatus">
            <tr>
              <td>
                <select name="statutselect1" required>
                  <option value="">choisir</option>
                  <option value="Professeur">Professeur</option>
                  <option value="Assistant">Assistant</option>
                </select>
                <input type="hidden" name="designationtypecadre1" value="EnseignementSuperieur" /> </td>
            </tr>
            <tr>
              <td>
                <select name="statutselect2">
                  <option value="">choisir</option>
                  <option value="Professeur">Professeur</option>
                  <option value="Assistant">Assistant</option>
                </select>
                <input type="hidden" name="designationtypecadre2" value="EnseignementSuperieur" /> </td>
            </tr>
            <tr>
              <td>
                <select name="statutselect3">
                  <option value="">choisir</option>
                  <option value="Professeur">Professeur</option>
                  <option value="ProfesseurConf">ProfesseurConf</option>
                  <option value="Assistant">Assistant</option>
                </select>
                <input type="hidden" name="designationtypecadre3" value="EnseignementSuperieur" /> </td>
            </tr>
            <tr></tr>
          </table>
        </td>
        <th>
          EnseignementSuperieur </th>
        </tr>
        <td>&nbsp;</td>
        <td>
          <input name="SubSommenbTitulaireTypeCadre" id="SubSommenbTitulaireProfChercheur" />
        </td>
        <td>
          <input name="SubSommenbFemaleTypeCadre" id="SubSommenbFemaleProfChercheur" />
        </td>
        <td>
          <input name="SubSommeNbProfTypeCadre" id="SubSommeNbProfChercheur" />
        </td>
        <td>
          <input name="SubSommeSalaireAnnuelTypeCadre" id="SubSommeSalaireAnnuelProfChercheur" />
        </td>
        <th>Somme SUB</th>
        <tr>
        </tr>
        <tr>
          <td>
            <input type="submit" name="Validate" value="Validate" />
          </td>
        </tr>
      </table>
  </body>
</html>
Community
  • 1
  • 1
jahounna
  • 49
  • 7
  • Instead of using `something.innerHTML = 'text'`, try using [`createElement()`](http://www.w3schools.com/jsref/met_document_createelement.asp) and [`appendChild()`](http://www.w3schools.com/jsref/met_node_appendchild.asp). – UndoingTech Apr 05 '16 at 16:43
  • 1
    What does `I have imbricated tables` and `recuperate the fields` mean? – j08691 Apr 05 '16 at 16:45
  • @j08691 it means that I don't have a simple table , inside a have another table ,for recuperate fields I meant I want to recuperate the value of the input fields filled by the user – jahounna Apr 06 '16 at 11:09
  • You're going to want to check out those words in a dictionary and re-phrase your question. – j08691 Apr 06 '16 at 12:22
  • English is not my first or second language so I am struggling :( – jahounna Apr 06 '16 at 13:40

0 Answers0