1 回答
TA贡献1828条经验 获得超4个赞
<select class="form-control" style="margin-bottom: 5px" id="myselectbox">
<option value="">Choix modèle de réponse</option>
@foreach($modeles as $modele)
<option value="{{ $modele->id }}">{{ $modele->title }}</option>
@endforeach
</select>
<textarea class="form-control" name="texte" id="texte" required>GRDF Bonjour</textarea>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).on('change','#myselectbox',function(){
var value = $(this).val(); // here is the selectbox value
$("#texte").val(value); // here put selectbox value in textarea
});
</script>
如果您有多次选择框和文本区域,则:-
@foreach($collection as $key => $item)
<select class="form-control selectbox" style="margin-bottom: 5px" id="myselectbox-{{$key}}">
<option value="">Choix modèle de réponse</option>
@foreach($modeles as $modele)
<option value="{{ $modele->id }}">{{ $modele->title }}</option>
@endforeach
</select>
<textarea class="form-control" name="texte" id="texte-{{$key}}" required>GRDF Bonjour</textarea>
@endforeach
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).on('change','.selectbox',function(){
var value = $(this).val();
var id = $(this).attr('id');
var key = id.substr(12);
$("#texte-"+key).val(value);
});
</script>
- 1 回答
- 0 关注
- 144 浏览
添加回答
举报