dongren7374 2018-07-09 03:37
浏览 77
已采纳

Laravel 5.6,如何在动态表单上设置var.SetAttibute的选项值?

Excuse me, I'm just learning web developing recently,

I have some trouble on dynamic form, here's the picture

I wanna make dynamic form with select type on it.

TAMBAH button = add more field Simpan button = save,

The problem is, when I want to add more fields, select input did not show as the first one, it become normal input not select.

I know, maybe the problem is from javascript which I don't understand.

here is the code

On Form

<td>{{ Form::text('jumlah[]', null, array('class'=>'form-control')) }}</td>
<td>{{ Form::text('satuan[]', null, array('class'=>'form-control')) }}</td>
<td>{{ Form::text('keterangan[]', null, array('class'=>'form-control')) }}</td>
{{ Form::select('status_pi[]', ['Iya' => 'iya', 'Tidak' => 'Tidak'],
'Tidak',array('class'=>'form-control')) }}

On Javascript

var jumlah = document.createElement('input');
jumlah.setAttribute('name', 'jumlah[' + i + ']');
jumlah.setAttribute('class', 'form-control');

var satuan = document.createElement('input');
satuan.setAttribute('name', 'satuan[' + i + ']');
satuan.setAttribute('class', 'form-control');

var keterangan = document.createElement('input');
keterangan.setAttribute('name', 'keterangan[' + i + ']');
keterangan.setAttribute('class', 'form-control');

var status_pi = document.createElement('input');
status_pi.setAttribute('name', 'status_pi[' + i + ']');
status_pi.setAttribute('selected', 'selected');
status_pi.setAttribute('class', 'form-control');

I wanna make var status_pi field appear like on the first one below PI column,

Pls help sensei

  • 写回答

1条回答 默认 最新

  • dowaw80220 2018-07-09 09:03
    关注
    var status_pi = document.createElement('input');
    

    Should be:

    var status_pi = document.createElement('select');
    

    As you can see here the input field is for textfields, and a select field is for dropdown menus.

    Keep in mind that you probably have to set your select's <option> values too in JavaScript.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀