【问题标题】:How to create a table, in which rows are filled in when a user submits a form如何创建一个表格,在用户提交表单时填写其中的行
【发布时间】:2011-11-25 05:29:27
【问题描述】:

我想创建两个单独的页面,一个带有 html 表单,另一个带有表格。当用户输入数据并提交表单时,我希望信息显示在表格中。

我是否需要使用 Javascript 或 PHP 来实现这一点。

任何帮助将不胜感激,

这是表格:

   <table border='1px' >

            <tr>
            <th>Location</th>
            <th>Time</th>
            <th>Date</th>
            </tr>
            <tr>
            <td  id='location1'>info</td>
            <td id="time1">info</td>
            <td id="date1">info</td>

            </tr>  
            <tr>
            <td id="location2">info</td>
            <td id="time2">info</td>
            <td id="date2">info</td>

            </tr>
            <tr>
            <td id="location3">info</td>
            <td id="time3">info</td>
            <td id="date3">info</td>
            </tr>
</table>

这是表格:

<form action="" method="post">
    Enter Location<input type="text" name="location" id="location" /><br />

    Time  <input type="text" name="" id="type" /><br />

    Date<input type="text" name="pitch" id="pitch" /><br />

    <input type="submit" name="submit" value="submit" /><br />
 </form>

【问题讨论】:

  • 您只是希望将这些信息放入网页上的表格中,还是也尝试将其存储在 SQL 表格中?
  • 是的,我只想将这些信息放入网页上的表格中,而不是 SQL 表格中

标签: javascript php html forms html-table


【解决方案1】:

您可以使用 php 或 javascript - php 会更容易恕我直言。最简单的代码示例可能如下所示:

<table border='1px' >

            <tr>
            <th>Location</th>
            <th>Time</th>
            <th>Date</th>
            </tr>
            <tr>
            <td  id='location1'><?php isset($_POST['location']) ? $_POST['location'] : '' ?></td>
            <td id="time1"><?php isset($_POST['time']) ? $_POST['time'] : '' ?></td>
            <td id="date1"><?php isset($_POST['pitch']) ? $_POST['pitch'] : '' ?></td>

            </tr>  
</table>

【讨论】:

  • 要显示单个帖子数据,此解决方案非常完美,但要跟踪该时间段内的每个帖子,逻辑会有所不同。
猜你喜欢
  • 2018-12-02
  • 1970-01-01
  • 1970-01-01
  • 2014-06-11
  • 2020-09-06
  • 1970-01-01
  • 1970-01-01
  • 2017-01-21
  • 1970-01-01
相关资源
最近更新 更多