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.

    点赞 打赏 评论

相关推荐 更多相似问题