Reputation: 429
I am having some trouble doing an if statement since most of the tutorial videos and other forums, I saw people only using variable, example $value, but I want to use if statement on the input name itself. Is that possible, if so could you help me out? Thanks a lot. Sorry if you are feeling confused of what I want maybe, if you see the code, you might understand, I don't really quite know how to say it in words.
test.blade.php
<div class="form-group">
<label class="col-md-2"><b>Test:</b></label>
<div class="col-md-6">
<input type="radio" name="test" value="Yes"> Yes<br>
<input type="radio" name="test" value="No"> No<br>
<input type="radio" name="test" value="Pending"> Pending<br>
</div>
@if(<input type="radio" name = "test" value="Yes"> || <input type="radio" name = "test" value="Pending">)
//show some other kind of input types such as :
<div class="form-group">
<label class="col-md-2"><b>Training Schedule:</b></label>
<div class="col-md-6">
<input type="radio" name="training_schedule" value="Yes"> Yes<br>
<input type="radio" name="training_schedule" value="No"> No<br>
</div>
@else
//make the other inputs value become NIL instead of showing
Something like:
name = "training_schedule" value = "NIL"
@endif
Upvotes: 0
Views: 1694
Reputation: 200
Here is the example using the javascript.
var test_input = $('input[name=test]');
var test_val = '';
var if_yes = '<div class="form-group"><label class="col-md-2"><b>Training Schedule:</b></label><div class="col-md-6"><input type="radio" name="training_schedule" value="Yes"> Yes<br><input type="radio" name="training_schedule" value="No"> No<br></div></div>';
var if_no = '<div class="form-group"><label class="col-md-2"><b>Training Schedule:</b></label><div class="col-md-6"><input type="radio" name="training_schedule" value="NIL"> NIL</div></div>';
$(test_input).on('change', function () {
test_val = $(this).val();
if (test_val == 'Yes' || test_val == 'Pending') {
//clear the div
$('div#append_to_this').html('');
// put your html code here
$('div#append_to_this').append(if_yes);
} else {
//clear the div
$('div#append_to_this').html('');
// put your html code here
$('div#append_to_this').append(if_no);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form">
<div class="form-group">
<label class="col-md-2"><b>Test:</b></label>
<div class="col-md-6">
<input type="radio" name="test" value="Yes"> Yes<br>
<input type="radio" name="test" value="No"> No<br>
<input type="radio" name="test" value="Pending"> Pending<br>
</div>
</div>
<br>
<div id="append_to_this"></div>
</div>
Upvotes: 1