dongshanjin8947 2013-09-30 23:31
浏览 18

是否可以使用PHP预填充动态html表的值?

Using the below code, i could pre-fill input elements of a form,

      <?PHP

       $filename = 'txt.txt';
     $str = file_get_contents($filename);
     for ($y=5; $y<=10;$y++){
     if($data[$y][0]=="PROJECT TITLE"){
    $projecttitle= $data[$y][1];}
      } ?>

          <tr>
  <th>Project Title: </th>
  <td><span class="dropt">
  <input id="projecttitle" onkeyup="ProjectTitleValidate()" value="<?php echo $projecttitle ?>" autocomplete="off" type="text" maxlength="50" name="projecttitle" title="Project Title for reference!">
  </td>
  </tr>

txt.txt for the above is,

 title: temp_12

but how to achieve that, for this kind of dynamic table,

    <script>
      function buildTable(val)
 {
 var myTable =document.getElementById("contentTable");
 var j=val;
 var r1=val;
var rows = [];
 var cells = [];

 while (myTable.hasChildNodes()) {
    myTable.removeChild(myTable.lastChild);
}


for( var i = 0; i < 1; i++ )
{
    rows[i] = myTable.insertRow(i);
    if(i%3==2)rows[i].addClass("every3rdrow");
    cells[i] = [];

    for( var x = 0; x < j ; x++ )
    {
        cells[i][x] =document.createElement((x==0)?"th":"td");
        cells[i][x].innerHTML = (x==0)?"<input id=t onchange=ty() name=t[] size=3>":"<input id=t1 onchange=ty1() name=t1[] size=3>";
        rows[rows.length - 1].appendChild(cells[i][x]);
    }
     }

      }
  buildTable(); 
 </script>

          <tr>
  <th>Number of Models:<title="Number of Models"></th>

  <td><select id="numbermodels" name="numbermodels" onmouseover="buildTable(this.value)" onchange="buildTable(this.value);buildTable4(this.value);">

  <option value="1">1</option >
  <option selected="selected" value="2">2</option >
  <option value="3">3</option >
  <option value="4">4</option >
  <option value="5">5</option >
  <option value="6">6</option >
  </select></td>
  </tr>

  <tr>
  <th>Number of heads per model:</th>
  <td>
  <table id="contentTable" border="1" name="contentTable">
    <!-- Fill table programmatically -->
</table></td>
  </tr>

and txt.txt file is

      Vector: 23 34 43 54

i tried to include php inside JavaScript input elements like value=, but this does not generate the table, is there any way to achieve this ?

  • 写回答

1条回答 默认 最新

  • dongzi3805 2014-01-05 08:57
    关注

    I'm more of a designer than programmer - so I'll offer a reply which may provoke some REAL programmers to respond.

    I found the following code while I've searched for developing automation of similar functions for event calendar and gallery pages on my website. My site needs various text details inserted into date coordinated info fields - combining calendar + event info, cross-linked.

    URL for SourceCode page with RSPA program: http://sourceforge.net/projects/rspa/files/

    RSPA is a component based event driven ajax enabled framework for PHP4 and PHP 5. It is a combination of plane PHP class and HTML.

    Using this framework you can call server side PHP class functions from client side control events. And in the server side function you can directly manipulate client side objects.

    I Use Prototype and script.aculo.us!

    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢