Laravel Blade Form, is it possible to create a textbox input if a user selects the 'other' option?

半世苍凉 提交于 2020-01-06 08:32:50

问题


This may not be possible with blade, but I was wondering how to generate a textbox input from an 'other' option in a select dropdown. Is this possible?

{{ Form::select('showType', array(
     'Theater' => 'Theater', 
     'Club' => 'Club',
     'Festival' => 'Festival',
     'Arena' => 'Arena',
     'Closed Show' => 'Closed Show',
     'College Show' => 'College Show'
     'Other' => 'some kind of text input appears instead'
  )}}

回答1:


You'll need to use javascript to do that, Blade can't help much. But you can create, in Blade, your form input and set a hidden class to it and, when your user select the 'other' option you just have to remove that class.




回答2:


You need to use JavaScript to do this because it happens on the client side. PHP and Laravel and Blade all happens on the server. An simple jQuery example:

$('select').on('change', function(){
  $('body').append("<input type='text' value='whatever'/>");
});


来源:https://stackoverflow.com/questions/22993691/laravel-blade-form-is-it-possible-to-create-a-textbox-input-if-a-user-selects-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!