elosh: Formulare beliebig oft erweitern

Hallo Leute,

kann mir vielleicht jemand helfen, ich bin am verzweifeln.

Ich hab folgende Idee( die ich nicht ganz realisieren kann):

Also ich hab ein ganz langes Formular.
An einer Stelle wird der Benutzer nach Informationen zu den Autoren gefragt( und zwar jeweils Name,Vorname,Email,Institution).
Da jedoch jedes Buch eine andere Anzahl von Autoren besitzen kann, dacht ich mir, dass der Benutzer durch einen "weitere Autor" - Button, diesen Teil des Formulars( ist bei mir eine Tabelle) beliebig oft hinzufügen kann.

Ist das irgenwie möglich bzw. WIE IST DAS MÖGLICH.

Ich kann jede Hilfe brauchen.

Danke elosh

  1. Hi,

    für DOM-fähige Browser geht das, indem Du zur Laufzeit entsprechende, neue Felder einhängst.
    Diesen Vorgang kannst Du dann beliebig oft wiederholen.

    Gruss
    Marcus

    1. Hallo Marcus,

      du ich versteh von Javascript net viel, ich hab eigentlich nur mit PHP programmiert. Kannst du mir mehr dazu sagen.

      Also, so in etwa soll der Teil aussehen, den ich beliebig oft ausfüülen möchte.

      <center>
      <td><table border="2" cellpadding="1" cellspacing="1">
      <tr>
      <td align right><b>Other Author(s)</b>
      </td></tr>
      <tr>
      <td align right><b>Author #1:</b>
      </td></tr><br>
      <td><table><td align right>Surname:<br>
      <input type="text" name="surname1" size="30"></td>
      <td align right>Name:<br>
      <input type="text" name="name1" size="30"></td>
      </tr>
      <tr>
      <td align right>Institution:<br>
      <input type="text" name="institution1" size="30"></td>
      <td align right>E-Mail:<br>
      <input type="text" name="email1" size="30"></td></table></td>
      </tr>

      Gruss
      Elnaz

      Hi,

      für DOM-fähige Browser geht das, indem Du zur Laufzeit entsprechende, neue Felder einhängst.
      Diesen Vorgang kannst Du dann beliebig oft wiederholen.

      Gruss
      Marcus

      1. Hi Elnaz,

        bitte sieh Dir mal die DOM-Referenz an:
        http://selfhtml.teamone.de/javascript/objekte/document.htm

        hier v.a. die Methoden die für das document Objekt zur Verfügung stehen.
        Da kommst Du nicht drum rum, weil es Dir nichts bringt, wenn Dir jemand sagt, wie Du genau ein bestimmtes Tabellenfragment neu erzeugst. Du willst ja auch Änderungen machen können! :)

        Danach helfe ich Dir gerne!

        Viele Grüße!
        Marcus

  2. abend,

    kann mir vielleicht jemand helfen, ich bin am verzweifeln.

    mal schauen..

    wenn ich dich jetzt recht verstanden habe benötigst du einen button,
    der gewisse formtags der aktuellen form hinzufügt.. ja?!
    folgender code realisiert oben genanntes:
    ---code---start---
    <HTML><TITLE>test</TITLE><HEAD>
    <SCRIPT language="JavaScript">
    function addTags() {
     FormTags = "Name :<input type=text name=name><br>" +
           "Vorname:<input type=text name=vorname><br>" +
           "Email:<input type=text name=email><br>";
     DivInhalt = document.getElementById("addarea").innerHTML;
     document.getElementById("addarea").innerHTML = DivInhalt + FormTags;
    }
    </SCRIPT>
    </HEAD>

    <BODY onLoad>
    <form name=fNa id=fNa>
    <p>
    Name :<input type=text name=name><br>
    Vorname:<input type=text name=vorname><br>
    Email:<input type=text name=email><br>
    <input type=button value=Add onClick="addTags()">

    <!-- PLATZHALTER -->
    <div id=addarea>
    </div>

    </form>
    </BODY>
    </HTML>
    ---code---ende

    das beispiel ist beileibe nicht ausgereift, funktioniert aber.

    mfg,
    (tanz das)
    Z.N.S.

    --
    <img src="http://www.dmp-web.de/comunicout/neubauten.gif" border="0" alt="">
    1. Hey, super!
      Danke dir!!!!!!

      Das müsste doch auch mit einer Tabelle funktionieren, oder.
      Also, so sollte es ungefähr aussehen:

      <!Doctype html Public"-//W3C//DTD HTML 4.01 Transitional//EN">
      <html><head>
      <title>Submission Form for Abstracts</title></head>
      <body>
      <div style="font-family:arial">
      <h2>Submission Form for Abstracts</h2>
      <form method="post" action="author.php">

      <center>
      <td><table border="2" cellpadding="1" cellspacing="1">
      <tr>
      <td align right><b>Other Author(s)</b>
      </td></tr>
      <tr>
      <td align right><b>Author #1:</b>
      </td></tr><br>
      <td><table><td align right>Surname:<br>
      <input type="text" name="surname1" size="30"></td>
      <td align right>Name:<br>
      <input type="text" name="name1" size="30"></td>
      </tr>
      <tr>
      <td align right>Institution:<br>
      <input type="text" name="institution1" size="30"></td>
      <td align right>E-Mail:<br>
      <input type="text" name="email1" size="30"></td></table></td>
      </tr>

      </table>
      </center></td>
      </div>
      </body></html>

      Wie erweitere ich den diesen Code?

      Gruss elosh

      1. abend,

        ---code anfang---
        <!Doctype html Public"-//W3C//DTD HTML 4.01 Transitional//EN">
        <html><head>
        <title>Submission Form for Abstracts</title>

        <script language="JavaScript">
        curAuthor = 2;
        function addAuthor(IndNr) {
         FormTags =  "<table><tr><td><b>Author #" + IndNr + "</b></td></tr><tr><td>Surname:<br>" +
                "<input type=text name=surname" + IndNr + " size=30></td>" +
               "<td>Name:<br><input type=text name=name" + IndNr + " size=30></td></tr>" +
               "</table></td></tr><tr><td><table><tr><td>Institution:<br>" +
               "<input type=text name=institution" + IndNr + " size=30></td>" +
               "<td>EMail:<br><input type=text name=email" + IndNr + "  size=30></td></tr></table><br>";
         DivInhalt = document.getElementById("HierWirdAngefuegt").innerHTML;
         document.getElementById("HierWirdAngefuegt").innerHTML = DivInhalt + FormTags;
         curAuthor++;
        }
        </script>

        </head>
        <body>

        <h2>Submission Form for Abstracts</h2>
        <form method="post" action="author.php">

        <center>
        <table border="2" cellpadding="1" cellspacing="1">
         <tr>
          <td><b>Other Author(s)</b></td>
         </tr>
         <tr>
          <td><b>Author #1:</b></td>
         </tr>
         <tr>
          <td>
           <table>
            <tr>
             <td>Surname:<br>
              <input type="text" name="surname1" size="30"></td>
             <td>Name:<br>
              <input type="text" name="name1" size="30"></td>
            </tr>
           </table>
          </td>
         </tr>
          <tr>
          <td>
           <table>
            <tr>
             <td>Institution:<br>
              <input type="text" name="institution1" size="30"></td>
             <td>EMail:<br>
              <input type="text" name="email1" size="30"></td>
            </tr>
           </table>
          </td>
         </tr>
         <tr><td id="HierWirdAngefuegt"></td></tr>
        </table>
        </center>

        <input type="button" name="add" value=add onClick="addAuthor(curAuthor)">

        </body></html>
        ---code---ende

        nur die feinheiten musst du schon selber machen ;) habe das script nur
        im IE getestet... viel spaß

        mfg,
        (tanz das)
        Z.N.S.

        --
        <img src="http://www.dmp-web.de/comunicout/neubauten.gif" border="0" alt="">
        1. Danke Danke Danke!

          Du bist ja richtig gut!

          Bist du öfter im Forum, so dass ich dich fragen kann, wenn ich wieder am verzweifeln bin?

          Gruss elosh

          1. abend,

            Danke Danke Danke!

            Bitte Bitte Bitte

            Du bist ja richtig gut!

            nicht so gut wie einige andere hier aber zum helfen reichts meißtens ;)

            Bist du öfter im Forum, so dass ich dich fragen kann, wenn ich
            wieder am verzweifeln bin?

            klar...

            Gruss elosh

            mfg,
            (tanz das)
            Z.N.S.

            --
            <img src="http://www.dmp-web.de/comunicout/neubauten.gif" border="0" alt="">
            1. ich hab da noch ne Frage.
              Wenn ich mal loslege zu fragen, kann ich net mehr aufhören.

              Davor hat ich eine feste Anzahl von Autoren und konnte die ohne Probleme in meine Datenbank eintragen.
              Jetzt, wo das dynamisch ist (du setzt da zwar überall die id hinten drann), weiss ich nicht so genau wie das geht.
              Wie kann ich denn im php-code meine Daten, die in meine db eingetragen werden dynamisch erweitern?

              Gruss elosh

              1. //hiermit kannst du dein problem lösen.. (kopier lieber diesen
                //quelltext anstatt den alten zu erneuern, da sich noch einiges
                //geändert hat...

                <!Doctype html Public"-//W3C//DTD HTML 4.01 Transitional//EN">
                <html><head>
                <title>Submission Form for Abstracts</title>

                <script language="JavaScript">
                curAuthor = 1;
                function addAuthor(IndNr) {
                 FormTags =  "<table><tr><td><b>Author #" + (IndNr+1) + "</b></td></tr><tr><td>Surname:<br>" +
                        "<input type=text name=surname[" + IndNr + "] size=30></td>" +
                       "<td>Name:<br><input type=text name=name[" + IndNr + "] size=30></td></tr>" +
                       "</table></td></tr><tr><td><table><tr><td>Institution:<br>" +
                       "<input type=text name=institution[" + IndNr + "] size=30></td>" +
                       "<td>EMail:<br><input type=text name=email[" + IndNr + "]  size=30></td></tr></table><br>";
                 DivInhalt = document.getElementById("HierWirdAngefuegt").innerHTML;
                 document.getElementById("HierWirdAngefuegt").innerHTML = DivInhalt + FormTags;
                 curAuthor++;
                }
                </script>

                </head>
                <body>

                <? if(!$doSQL) { ?>
                <h2>Submission Form for Abstracts</h2>
                <form method="post" action="test.php">
                <center>
                <table border="2" cellpadding="1" cellspacing="1">
                 <tr>
                  <td><b>Other Author(s)</b></td>
                 </tr>
                 <tr>
                  <td><b>Author #1:</b></td>
                 </tr>
                 <tr>
                  <td>
                   <table>
                    <tr>
                     <td>Surname:<br>
                      <input type="text" name="surname[0]" size="30"></td>
                     <td>Name:<br>
                      <input type="text" name="name[0]" size="30"></td>
                    </tr>
                   </table>
                  </td>
                 </tr>
                  <tr>
                  <td>
                   <table>
                    <tr>
                     <td>Institution:<br>
                      <input type="text" name="institution[0]" size="30"></td>
                     <td>EMail:<br>
                      <input type="text" name="email[0]" size="30"></td>
                    </tr>
                   </table>
                  </td>
                 </tr>
                 <tr><td id="HierWirdAngefuegt"></td></tr>
                </table>
                </center>
                <input type="button" name="add" value=add onClick="addAuthor(curAuthor)">
                <p>
                <input type="submit" name="doSQL" value="SQL-generieren">
                </form>
                <? } else {

                for($i=0; $i<sizeof($surname); $i++) {
                 echo "INSERT into TABELLE (surname,name,institution,email) VALUES ('";
                 echo $surname[$i]."','".$name[$i]."','".$institution[$i]."','".$email[$i]."');<br>";
                }

                } ?>

                </body></html>