There is an object:

@foreach( $data as $row ) <div class='row' style='clear:both;width:1200px;'> @foreach( $row as $day=>$gymArray ) <div class='cell' style='width:170px;float:left;;text-align: center;max-height:370px;overflow: auto'> @foreach( $gymArray as $gym=>$gymInfo ) <div id="timetable-cell-gym" style='clear:both'> <p id="time-text">{{ $gymInfo[ 'time' ] or '' }}</p><hr id="hr-time" style="width:20%"/> <h5 style="margin-bottom: -6px; margin-top:-10px"><strong id="group-name">{{ $gymInfo[ 'group' ] or '' }}</strong></h5><br> {{ $gymInfo[ 'trainer' ] or '' }}<br><hr id="after-worker-line" style="width:70%; margin-bottom: 15px"/> <p style="margin-top: 9px"> {{ $gymInfo[ 'status' ] or '' }}</p> <small id="gym-name">{{ $gym or '' }}</small> </div> @endforeach </div> @endforeach </div> @endforeach 

When editing the form, the status select is displayed:

 {!! Form::model($columns, ['class' => 'form', 'method' => 'PUT', 'route' => ['api.columns.update']]) !!} <input name="id" value="{!! $columns->id !!}" type="hidden"> <div class="form-group"> {!! Form::label('time', 'время', ['class' => 'control-label']) !!} {!! Form::text('time', null, ['class' => 'form-control']) !!} <p class="help-block">в формате: "8:25"</p> </div> <div class="form-group"> {!! Form::label('service_title', 'группа', ['class' => 'control-label']) !!} {!! Form::select('service_title', $groups, null, ['class' => 'form-control']) !!} </div> <div class="form-group"> {!! Form::label('worker_name', 'Тренер', ['class' => 'control-label']) !!} {!! Form::select('worker_name', $trainers, null, ['class' => 'form-control']) !!} </div> <div class="form-group"> {!! Form::label('timetable-select', 'статус', ['class' => 'timetable-select']) !!} {!! Form::select('timetable-select', $status, old('status'), ['class' => 'form-control']) !!} </div> <div class="buttons" align="right"> {!! Form::submit('Обновить', ['class' => 'btn btn-primary']) !!} <a class="btn btn-default" href="{{ url('api/columns') }}" style="background: #832032; color: #fffbd8;">Назад</a> {!! Form::close() !!} </div> 

It is necessary that when saving changes in this form, the status of an object is assigned. At the moment I tried this version of JS:

 $(document).ready(function(){ if ($("#timetable-select").change){ className = $(this).val(); oldClassName = $("#timetable-cell-gym").attr("oldClass"); $("#timetable-cell-gym").attr("oldClass",className); $("#timetable-cell-gym").removeClass(oldClassName).addClass(className); } }); 

When updating the class of the object has not changed. How can I change the script for its performance?

  • Are you sure this is javascript? - Visman
  • @Visman and there are other options? - bastadien
  • What other options if I asked "where does javascript come from?". The code you presented in the question does not pull on javascript, that's all. - Visman
  • @Visman fixed the post, I hope so clearer - bastadien
  • You write #timetable-select (id) in the js script, and as I understood from the markup you have class="timetable-select" , it should be necessary .timetable-select - Alexander Igorevich

1 answer 1

Updated.
Thanks @VenZell. I did not notice that .timetable-select is a class label , and not select , therefore the change event on it is useless to hang.

It is worth manipulating with the select tag.

You can use ~ :

 $('.timetable-select ~ select:first').on('change', function() { className = $(this).val(); $("#timetable-cell-gym").attr("class", className) }); 
  • Still does not change the class - bastadien
  • 2
    Alexander, note that the class .timetable-select hung on the label . That is why, firstly, the change event does not work when a value is selected in the drop-down list, and secondly the val() method does not return anything. This class must be attached to a select tag. Add this in response. - VenZell
  • @bastadien updated the answer - Alexander Igorevich
  • @AlexanderIgorevich unfortunately continues to resist and does not assign a class to an object - bastadien
  • @bastadien take a look at the "live" jsfiddle example. You may see a difference in something. - Alexander Igorevich