Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在laravel中编辑时保持选择选项值处于选中状态_Javascript_Php_Jquery_Laravel_Select - Fatal编程技术网

Javascript 在laravel中编辑时保持选择选项值处于选中状态

Javascript 在laravel中编辑时保持选择选项值处于选中状态,javascript,php,jquery,laravel,select,Javascript,Php,Jquery,Laravel,Select,我试图在编辑过程中保持选择选项值处于选中状态。在那里,我使用javascript作为动态相关下拉列表。但现在我面临一个问题,在编辑过程中保持选项值处于选中状态。有人能帮我解决这个问题吗编辑.blade.php- <form class="form-material form-horizontal" action="{{ route('admin.commercial.orders.update', $order->id) }}" method="POST"> @me

我试图在编辑过程中保持选择选项值处于选中状态。在那里,我使用javascript作为动态相关下拉列表。但现在我面临一个问题,在编辑过程中保持选项值处于选中状态。有人能帮我解决这个问题吗<代码>编辑.blade.php-

<form class="form-material form-horizontal" action="{{ route('admin.commercial.orders.update', $order->id) }}" method="POST">
      @method('PUT')    
      @csrf
   <div class="row">
      <div class="col-md-6">
           <div class="form-group">
              <label class="col-md-12" for="name">Buyer Name: </label>
              <div class="col-md-12">
                 <select class="form-control select2" name="name" id="buyerName">
                     <option value="">Select Buyer</option>
                 </select>
                  @if ($errors->has('name'))
                     <small class="error">{{ $errors->first('name') }}</small>
                  @endif
              </div>
          </div>
      </div>
      <div class="col-md-6">
           <div class="form-group">
             <label class="col-md-12" for="job_name">Job Name/Title: </label>
             <div class="col-md-12">
                  <select class="form-control select2" name="job_name" id="jobName">
                      <option value="">Select Job</option>
                  </select>

                   @if ($errors->has('job_name'))
                      <small class="error">{{ $errors->first('job_name') }}</small>
                   @endif
              </div>
        </div>

      </div>
    </div>
 </form>

将其添加到javascript的底部

$("#buyerName").val("{{old('name')}}");
$("#jobName").val("{{old('job_name')}}");`
你可以试试这个主意:

<select name="buyer">
  @foreach(['buyer1', 'buyer2', 'buyer3'] as $buyer)
    <option vlaue="{{ $buyer }}"{{ (old('buyer') == $buyer) ? ' selected' : '' }}>{{ $buyer }}</option>
  @endforeach
</select>

@foreach(['buyer1'、'buyer2'、'buyer3']作为$buyer)
{{$buyer}
@endforeach

<select name="buyer">
  @foreach(['buyer1', 'buyer2', 'buyer3'] as $buyer)
    <option vlaue="{{ $buyer }}"{{ ($order->buyer == $buyer) ? ' selected' : '' }}>{{ $buyer }}</option>
  @endforeach
</select>

@foreach(['buyer1'、'buyer2'、'buyer3']作为$buyer)
买方==$买方)?'所选“:”}>{{$buyer}}
@endforeach

您所说的“在编辑期间”是什么意思?“在编辑期间”我想用特定
订单的旧数据保持选择选项处于选中状态
id这不符合我的要求,因为您使用的是laravel,您可以只使用旧输入。阅读
选择中的
选项是什么?请在调用
DynamicDropdown
后包含它。如果运行
console.log({{old('name')}})
它会输出您想要的吗?
<select name="buyer">
  @foreach(['buyer1', 'buyer2', 'buyer3'] as $buyer)
    <option vlaue="{{ $buyer }}"{{ (old('buyer') == $buyer) ? ' selected' : '' }}>{{ $buyer }}</option>
  @endforeach
</select>
<select name="buyer">
  @foreach(['buyer1', 'buyer2', 'buyer3'] as $buyer)
    <option vlaue="{{ $buyer }}"{{ ($order->buyer == $buyer) ? ' selected' : '' }}>{{ $buyer }}</option>
  @endforeach
</select>