复制当前输入字段,并在同一页的表中添加额外的行

时间:2018-10-10 16:50:34

标签: php mysql html-table

如果用户按下按钮“ pievienot vel”,则需要能够添加无限的输入字段,如果按下按钮,还需要添加更多表行。对不起,如果答案在某个地方,就找不到它。目前,我只能再按一次在表bu中添加一个输入字段和一行。 同样是PHP和html的新手,所以不要判断我的代码:)

需要任何帮助! :)

    <h3> Personīgā informācija </h3> 

<div id="Personal">

    <label>Vārds: </label>
    <input name="Name" type="text" size ="30"
     <?php
    if(isset($_POST['create'])) {
        echo "value='".$_POST['Name']."'";
    } else {
        echo "placeholder='Vārds'";
    }
    ?>  

    /> <br /><br />

    <label>Uzvārds: </label>
    <input name="Surname" type="text" size ="30" value="" placeholder='Uzvārds' /> <br /><br />

    <label>Dzimšanas gads: </label>
    <input name="DOB" type="text" size ="15" value="" placeholder="Dzimšanas Gads"  /> <br /><br />

    <label>E-pasts: </label>
    <input name="Email" type="text" size ="30" value="" placeholder="E-pasta adrese" /> <br /><br />

</div>

    <h3> Izglītības informācija 
    <button class="educationbtn" name="education" onclick="addText();" > Pievienot vel </button>
    </h3> 
<div id="Education" name="Educationdiv">

    <label>Iestādes nosaukums: </label>
    <input name="EdName[]" type="text" size ="30" value="" placeholder="Iestādes nosaukums" /> <br /><br />

    <label>Gads no - līdz: </label>
    <input name="Year1[]" type="text" size ="10" value="" placeholder="No" />
    <input name="Year2" type="text" size ="10" value="" placeholder="Līdz"  /> <br /><br />

    <label>Specialitāte: </label>
    <input name="Specialitate[]" type="text" size ="30" value="" placeholder="Specialitāte"  /> <br /><br />

</div>

    <?php

    if(isset($_POST['education']))
    { 
    ?>
    <label>Iestādes nosaukums: </label>
    <input name="EdName[]" type="text" size ="30" value="" placeholder="Iestādes nosaukums" /> <br /><br />

    <label>Gads no - līdz: </label>
    <input name="Year1[]" type="text" size ="10" value="" placeholder="No" />
    <input name="Year2" type="text" size ="10" value="" placeholder="Līdz"  /> <br /><br />

    <label>Specialitāte: </label>
    <input name="Specialitate[]" type="text" size ="30" value="" placeholder="Specialitāte"  /> <br /><br />

    <?php 

    }
    ?>
    <h3> Valodu zināšanu informācija 
    <button class="languagebtn" name="language"> Pievienot vel </button>
    </h3> 

<div id="Language">

    <table style="center" style="width:100%">

    <tr>
    <th> Valoda </th>
    <th> Runātprasme </th>
    <th> Lasītprasme </th>
    <th> Rakstītprasme </th>
    </tr>

    <tr>
    <td> <input name="Lvtext" type="text" size ="10" value="Latviešu"  readonly /> </td></td>
    <td> <input name="LvRunat" type="text" size ="20" value=""  /> </td>
    <td> <input name="LvLasit" type="text" size ="20" value=""  /> </td>
    <td> <input name="LvRakstit" type="text" size ="20" value=""  /> </td>
    </tr>

    <tr>
    <td> <input name="Engtext" type="text" size ="10" value="Angļu" readonly  /> </td></td>
    <td> <input name="EngRunat" type="text" size ="20" value=""  /> </td>
    <td> <input name="EngLasit" type="text" size ="20" value=""  /> </td>
    <td> <input name="EngRakstit" type="text" size ="20" value=""  /> </td>
    </tr>

    <tr>
    <td> <input name="Rustext"type="text" size ="10" value="Krievu" readonly /> </td></td>
    <td> <input name="RusRunat" type="text" size ="20" value=""  /> </td>
    <td> <input name="RusLasit" type="text" size ="20" value=""  /> </td>
    <td> <input name="RusRakstit" type="text" size ="20" value=""  /> </td>
    </tr>

    <?php

        if(isset($_POST['language']))
        {
        ?>
        <tr>
        <td> <input name="Extext"type="text" size ="10" value=""  /> </td></td>
        <td> <input name="ExRunat" type="text" size ="20" value=""  /> </td>
        <td> <input name="ExLasit" type="text" size ="20" value=""  /> </td>
        <td> <input name="ExRakstit" type="text" size ="20" value=""  /> </td>
        </tr>
            <?php
        }
    ?>

    </table> 
    <br /><br />

</div>

<input type="submit" name="create" class="button" size="10" value="Create CV" />
<br /><br />
<br /><br />

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

<script>
var count = 0;
function addNewInput(){

  var eDiv = document.getElementById('Education');
  var newInput = document.createElement('input');

  newInput.setAttribute('id', 'newInput'+ count);

  eDiv.appendChild(newInput);

  count++;

}
</script>

然后,您可以在所需的按钮中使用属性onClick ='addNewInput'。

这是一个示例,但我认为这可以使您了解如何使用javascript编写表单。希望它能对您有所帮助。