Support the ongoing development of Laravel.io →
Views Forms
Last updated 2 years ago.
0

Best idea is javascript.

I'm guessing that your using jQuery, as the form looks bootstrap-ish.

Try this,

<html>
    <head>
        <title>test</title>
        
        <script src="jquery-1.12.0.min.js"></script>
        
        <script>
        
        $(function() {
        
            // run on change for the selectbox
            $( "#frm_duration" ).change(function() {  
                updateDurationDivs();
            });
            
            // handle the updating of the duration divs
            function updateDurationDivs() {
                // hide all form-duration-divs
                $('.form-duration-div').hide();
                  
                var divKey = $( "#frm_duration option:selected" ).val();                
                $('#divFrm'+divKey).show();
            }        
        
            // run at load, for the currently selected div to show up
            updateDurationDivs();
        
        });
        </script>
        
    </head>
    <body>
       
    <form>
    <div class="form-group">
        <label class="col-md-3 control-label">Duration </label>
        <div class="col-md-9">
            <select class="form-control" id="frm_duration">
                <option value="Monthly">Monthly</option>
                <option value="Quarterly">Quarterly</option>
                <option value="HalfYearly">Half Yearly</option>
                <option value="Yearly">Yearly</option>         
            </select>
        </div>
    </div>
    <div id="divFrmMonthly" class="form-group form-duration-div" style="display:none">
        <label class="col-md-3 control-label">Monthly</label>
        <div class="col-md-9">
        <input type="text" class="form-control" placeholder="Monthly" > </div>
    </div>
    <div id="divFrmQuarterly" class="form-group form-duration-div" style="display:none">
        <label class="col-md-3 control-label">Quarterly</label>
        <div class="col-md-9">
        <input type="text" class="form-control " placeholder="Quarterly" > </div>
    </div>
    <div id="divFrmHalfYearly" class="form-group form-duration-div" style="display:none">
        <label class="col-md-3 control-label">Half Yearly</label>
        <div class="col-md-9">
        <input type="text" class="form-control" placeholder="Half Yearly" > </div>
    </div>
    <div id="divFrmYearly" class="form-group form-duration-div" style="display:none">
        <label class="col-md-3 control-label">Yearly</label>
        <div class="col-md-9">
        <input type="text" class="form-control" placeholder="Yearly" > </div>
    </div>

    </form> 
    </body>    
</html>

0

Many thanks @terreporter,

Yes i'm using bootstrapping in blade layout. its worked out.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.