How can I show a part of form after a yes/no radio?

Isumairu


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).

Nitin Khanna

You can use .change for what you want

$("input[@name='lom']").change(function(){
    // Do something interesting here
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I show the output vertically after submitting the html form?

How can I make this loader show only after form validation?

How can I reset a form field and show Success or Thanks you after form submission?

how can I put the comment show on form

How can I show/hide form with checkbox?

How can I show messages depending on selected radio buttons?

how can i show list view as a horizontal radio list tile?

How can I show form error one after the other ? (Condition 'elseif' not working)

How can I make a form inputs disabled by pressing a radio button?

How do I customize MessageBoxButtons.YesNo so that if they click on "Yes" or "No" to show a message box with information

why can't i show form after it was hidden?

How do I associate an Angular Material radio button with a form control if I can't use a radio group?

how can i show a part of log file in latex

How can I redirect to a form after an alert?

How can I hide a form after submission?

Need to submit choice ID as part of a form, how can I do this?

Django: How can I organize common form submisson part into a function?

The radio buttons and checkbox do not show the alert message after clicking, Can you look if I made a mistake?

How to show radio button after selecting option

How can I clear form values after successful form submission

How I can get the other part after a division with a modulo operator

How can I hide short part of div which is inside the container but show another overflow part

how can I return value from show dialog form?

How can I show error message in login form modal?

how can i show form fields on clicking the link?

How can I show specific data un my Django form?

How can I show and hide the form in HTML page?

How can I make a form in Chrome extension show only once?

How many controls can I create and show in a Windows Forms form?