drxpt06820 2013-10-30 22:50
浏览 6
已采纳

从.txt文件填充表单中的选项值

I have a form that I am creating for basic time submission at a company. However, I need to design one part so that the owner can simply load up a .txt file or an excel document or something similar and replace and edit names real quick for the drop down field.

The current code:

<select name="entry.44832674" id="entry_44832674" aria-required="true" required="">
          <option value=""></option>
          <option value="Option 1">Option 1</option>
          <option value="Option 2">Option 2</option>
          <option value="Option 3">Option 3</option>
          <option value="Option 4">Option 4</option>
          <option value="Option 5">Option 5</option>
        </select>

Is this possible to perform with php or javascript of some sort? Would like to keep this as simple as possible as the owner does not have time to mess with code. If possible to create a simple .txt file in the format of

Option 1
Option 2
Option 3
Option 4
Option 5

and then the owner can add or remove names when needed that would be awesome. I have found many solutions for things, but could not find an answer for this one.

  • 写回答

2条回答 默认 最新

  • dpw63348 2013-10-30 22:57
    关注

    Something like this should do it:

    <select>
    <option value=""></option>
    
    <?php
    $options=nl2br(file_get_contents("optionsTextFile.txt"));
    $options=explode("<br>",$options);
    
    for($i=0;$i<count($options);$i++)
      {
      echo "<option value='".$options[$i]."'>".$options[$i]."</option>";
      }
    ?>
    
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀