My javascript code like this :
$('input[name="is_follow_up"]').change(function(){
var val = $(this).val(),
input = $('.input-reason');
if (val == 'n')
input.show()
else
input.hide();
});
$('.select-reason').change(function(){
var reason = $(this).val(),
others = $('.textarea-others');
if (reason == 4) {
others.show();
$(this).removeAttr('name');
others.find('textarea').attr('name', 'reason');
}
else {
others.hide()
$(this).attr('name', 'reason');
others.find('textarea').removeAttr('name');
}
});
My html code like this :
@foreach($orders as $order)
...
<label class="radio-inline">
<input type="radio" name="is_follow_up" id="inlineRadio1" value="y" required checked> accept
</label>
<label class="radio-inline">
<input type="radio" name="is_follow_up" id="inlineRadio2" value="n" required> reject
</label>
<div class="row input-reason" style="display: none">
<div class="col-sm-2">Reason:</div>
<div class="col-sm-5">
<div class="form-group">
<select class="form-control select-reason" name="reason">
<option value="Reason 1">Reason 1</option>
<option value="Reason 2">Reason 2</option>
<option value="Reason 3">Reason 3</option>
<option value="4">Reason 4</option>
</select>
</div>
<div class="form-group textarea-others" style="display: none">
<textarea rows="5" class="form-control"></textarea>
</div>
</div>
</div>
...
@endforeach
If I have 5 data order. there will be 5 iterations. If I choose reject in first iteration, it will show textarea in all iteration
I want :
If user selects reject in the first iteration, it only show textarea in the first iteration
If user selects reject in third iteration, it only show textarea in third iteration
etc
How can I do it?