Well my question is as the title says , specifically I have a form that I store on a database and not all the fields are required , more specifically we are selling products and there is a promo price that can be added but I don’t want to show the input place for the promo price until I get a answer (if yes then show it else no need to show that part of the form) how can I process that ?
I am working on laravel (I use basic php at the moment because I am still learning) if that helps.
Edit : After some search I found a script that I tried adapting to my code , here is the new version :
<h1>Add a new product</h1>
<form id="someform" method="post" action="/managers">
{{ csrf_field() }}
{{-- the csrf is used for security purposes ps: we can't proceed without it , it gives error 419--}}
<div>
<select name="market">
@foreach($marketname as $mname)
<option name="market" value="{{$mname->managerId}}">{{$mname->name}}</option>
@endforeach
</select>
</div>
<div>
<input type="text" name="name" placeholder="Product name">
</div>
<div>
<input type="text" name="price" placeholder="Price (mad)">
</div>
<h5>Is there a promo on the product</h5>
<input type="radio" name="quest" id="rad">
<label for="Yes">Yes</label>
<input type="radio" name="quest" value="No">
<label for="No">No</label>
<div class="test">
<input type="text" name="promo" placeholder="Promo price">
<label style="display:block">The promo end date:</label>
<input type="date" name="promod">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
$(function () {
$('.test').hide();
$("input[name=quest]:radio").click(function () {
if ($('input[name=quest]:checked').val() == "Yes") {
$('.test').show();
} else if ($('input[name=quest]:checked').val() == "No") {
$('.test').hide();
}
});
});
</script>
<div>
<button type="submit">Add product</button>
</div>
</form>
The problem is nothing happens , I read that we can’t use js on blade files , how can I use it then (I don’t know js I just copied and edited).
2
Answers
use javascript
onclick of the radio button then produce another element you want to show
You can use .change for what you want