1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
<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>
如果您有多次選擇框和文本區(qū)域,則:-
@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 關(guān)注
- 172 瀏覽
添加回答
舉報(bào)