mercredi 20 décembre 2017

Get checked box value without submission php

i have a form divided into 3 divs, the second div's result is based upon a checkbox from the first one, i'm trying to get the value of the checked item but having no success so far, the form is not submitted until the last div appears (using onclick functions to hide a div and show the other), i don't want to post the values not to get redirected to the first div again, here's a code snippet :

  <div class="form-group">
                        <label style="text-align: left;" class="control-label col-sm-3">Type</label>
                        <div class="col-sm-3">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" id="checkbox1" name="type" value="Employee">Employee
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" id="checkbox2" name="type" value="Teacher">Teacher
                                </label>
                            </div>

                        </div>

    <script>var checkedValue = $('.checkbox:checked').val();</script>
                    </div> <!-- /.form-group -->
    </div>
    <button  type="button" class='btn btn-success' onclick="switchVisible();">Next</button>
    </div>
                    <!-- now we want to start the targeted form ( teacher or emp ) but should be invisible at first -->
                    <div id="targetedform" class="container" style="display:none;">

    <div  class="jumbotron" style="margin-top: 10px; padding-left:0px !important; ">
        <h3 style="color:black;">Employment Information</h3></div>
<script > document.write(checkedValue);</script>

Under Employment Information , i want to put an if statement based on the checked value ( either Teacher or Employee ) to output their corresponding data, i tried var checkedValue = $('.checkbox:checked').val(); as suggested in Get the value of checked checkbox? but .write(checkedValue) has undefined as result, i'm not sure of its scope, any tips please ?




Aucun commentaire:

Enregistrer un commentaire