验证单选按钮和必需的字段jQuery

时间:2015-01-20 18:03:32

标签: php jquery html radio-button validity.js

我使用http://validity.thatscaptaintoyou.com/Demos/index.htm并且我遇到了require-radio问题。

如果您希望输入字段是强制性的,则可以正常工作。

但是我需要看到这些字段是强制性的无线电,此外,如果用户选择值为2或5的无线电,则还必须填写必填输入文本字段。

例如,我在“prowadzenie_zajec”注意到2,我填写了“k_prowadzenie_zajec”框。

有人可能遇到过问题或可以提供帮助吗?

 <html>
        <head>
            <title>
                Student: Studencka ankieta oceny nauczycieli akademickich
            </title>
            <meta charset="UTF-8"/>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
            <script src="http://malsup.github.com/jquery.form.js"></script> 
            <link rel="Stylesheet" href="../css/jquery.validity.css" />
            <script src="../js/jquery.validity.min.js"></script>
            <link href="../css/style_ankiety.css" rel="stylesheet" />
        </head>
        <?php              
        $query = "SELECT * FROM student_ankieta WHERE `id_student`='$user_data[id_student]' AND data_wypelnienia IS NULL";
        $result = mysql_query($query);              
        while ($row = mysql_fetch_array($result)) 
        {
            echo'   <div class="ankieta">
                    <script>
                        $(function() 
                        {
                            $("#formularz' . $row['id_student_ankieta'] . '").validity(function() 
                            {
                                $("#przygotowanie_zajec' . $row['id_student_ankieta'] . '").require().match("number");
                                $("#k_przygotowanie_zajec' . $row['id_student_ankieta'] . '").require("Dodaj komentarz");
                                $("#prowadzenie_zajec' . $row['id_student_ankieta'] . '").require();
                                $("#k_prowadzenie_zajec' . $row['id_student_ankieta'] . '").require("Dodaj komentarz");
                                $("#ocenianie_studentow' . $row['id_student_ankieta'] . '").require();
                                $("#k_ocenianie_studentow' . $row['id_student_ankieta'] . '").require("Dodaj komentarz");
                                $("#stosunek_do_studentow' . $row['id_student_ankieta'] . '").require();
                                $("#k_stosunek_do_studentow' . $row['id_student_ankieta'] . '").require("Dodaj komentarz");
                                $("#obecnosc_studenta' . $row['id_student_ankieta'] . '").require();
                                $("#ocena_zajecia' . $row['id_student_ankieta'] . '").require();
                            });   
                        });  
                    </script>
                    ';

                    echo '<span id="success' . $row['id_student_ankieta'] . '" style="display: none;color:green;">Wysłano!</span>
                    <script> 
                        $(document).ready(function() 
                        { 
                            $("#formularz' . $row['id_student_ankieta'] . '").ajaxForm(function() {
                                    $("#formularz' . $row['id_student_ankieta'] . '").fadeOut( "slow" );
                                    $("#success' . $row['id_student_ankieta'] . '").css({"display":"block"});
                            }); 
                        }); 
                     </script>

                    <label>
                            <span>Przygotowanie zajec:</span>
                    </label>
                    <input type="radio" value="2" name="przygotowanie_zajec' . $row['id_student_ankieta'] . '" id="przygotowanie_zajec' . $row['id_student_ankieta'] . '">5
                    <input type="radio" value="3" name="przygotowanie_zajec' . $row['id_student_ankieta'] . '" id="przygotowanie_zajec' . $row['id_student_ankieta'] . '">4
                    <input type="radio" value="4" name="przygotowanie_zajec' . $row['id_student_ankieta'] . '" id="przygotowanie_zajec' . $row['id_student_ankieta'] . '">3
                    <input type="radio" value="5" name="przygotowanie_zajec' . $row['id_student_ankieta'] . '" id="przygotowanie_zajec' . $row['id_student_ankieta'] . '">2

                    <label>
                            <span><br/></span>
                    </label>
                        <input maxlength="250" class="wpis" name="k_przygotowanie_zajec' . $row['id_student_ankieta'] . '" id="k_przygotowanie_zajec' . $row['id_student_ankieta'] . '">
                    <label>
                            <span>Prowadzenie <br/> zajęć:</span>
                    </label>
                    <input type="radio" value="2" name="prowadzenie_zajec' . $row['id_student_ankieta'] . '" id="prowadzenie_zajec' . $row['id_student_ankieta'] . '">5
                    <input type="radio" value="3" name="prowadzenie_zajec' . $row['id_student_ankieta'] . '" id="prowadzenie_zajec' . $row['id_student_ankieta'] . '">4
                    <input type="radio" value="4" name="prowadzenie_zajec' . $row['id_student_ankieta'] . '" id="prowadzenie_zajec' . $row['id_student_ankieta'] . '">3
                    <input type="radio" value="5" name="prowadzenie_zajec' . $row['id_student_ankieta'] . '" id="prowadzenie_zajec' . $row['id_student_ankieta'] . '">2

                    <label>
                            <span><br/></span>
                    </label>
                        <input maxlength="250" class="wpis" name="k_prowadzenie_zajec' . $row['id_student_ankieta'] . '" id="k_prowadzenie_zajec' . $row['id_student_ankieta'] . '">
                        </textarea>
                    <label>
                            <span>Ocenianie studentów:</span>
                    </label>
                        <input type="radio" value="2" name="ocenianie_studentow' . $row['id_student_ankieta'] . '" id="ocenianie_studentow' . $row['id_student_ankieta'] . '">5
                        <input type="radio" value="3" name="ocenianie_studentow' . $row['id_student_ankieta'] . '" id="ocenianie_studentow' . $row['id_student_ankieta'] . '">4
                        <input type="radio" value="4" name="ocenianie_studentow' . $row['id_student_ankieta'] . '" id="ocenianie_studentow' . $row['id_student_ankieta'] . '">3
                        <input type="radio" value="5" name="ocenianie_studentow' . $row['id_student_ankieta'] . '" id="ocenianie_studentow' . $row['id_student_ankieta'] . '">2

                    <label>
                            <span><br/></span>
                    </label>
                        <input maxlength="250" class="wpis" name="k_ocenianie_studentow' . $row['id_student_ankieta'] . '" id="k_ocenianie_studentow' . $row['id_student_ankieta'] . '">
                        </textarea>
                    <label>
                            <span>Stosunek do studentów:</span>
                    </label>
                        <input type="radio" value="2" name="stosunek_do_studentow' . $row['id_student_ankieta'] . '" id="stosunek_do_studentow' . $row['id_student_ankieta'] . '">5
                        <input type="radio" value="3" name="stosunek_do_studentow' . $row['id_student_ankieta'] . '" id="stosunek_do_studentow' . $row['id_student_ankieta'] . '">4
                        <input type="radio" value="4" name="stosunek_do_studentow' . $row['id_student_ankieta'] . '" id="stosunek_do_studentow' . $row['id_student_ankieta'] . '">3
                        <input type="radio" value="5" name="stosunek_do_studentow' . $row['id_student_ankieta'] . '" id="stosunek_do_studentow' . $row['id_student_ankieta'] . '">2

                    <label>
                            <span><br/></span>
                    </label>
                        <input maxlength="250" <input class="wpis" name="k_stosunek_do_studentow' . $row['id_student_ankieta'] . '" id="k_stosunek_do_studentow' . $row['id_student_ankieta'] . '">
                        </textarea>
                    <label>
                            <span>Obecność <br/> na zajęciach:</span>
                    </label>
                        <input type="radio" value="100" name="obecnosc_studenta' . $row['id_student_ankieta'] . '" id="obecnosc_studenta' . $row['id_student_ankieta'] . '">poniżej 50%
                        <input type="radio" value="80" name="obecnosc_studenta' . $row['id_student_ankieta'] . '" id="obecnosc_studenta' . $row['id_student_ankieta'] . '">ok. 60%
                        <input type="radio" value="60" name="obecnosc_studenta' . $row['id_student_ankieta'] . '" id="obecnosc_studenta' . $row['id_student_ankieta'] . '">ok. 80%
                        <input type="radio" value="50" name="obecnosc_studenta' . $row['id_student_ankieta'] . '" id="obecnosc_studenta' . $row['id_student_ankieta'] . '">ok. 100%

                    <label>
                            <span><br/>Ocena z zajęć:</span>
                    </label>
                        <input type="radio" value="5" name="ocena_zajecia' . $row['id_student_ankieta'] . '" id="ocena_zajecia' . $row['id_student_ankieta'] . '">3,0 - 2,0
                        <input type="radio" value="4" name="ocena_zajecia' . $row['id_student_ankieta'] . '" id="ocena_zajecia' . $row['id_student_ankieta'] . '">4,0 - 3,5
                        <input type="radio" value="3" name="ocena_zajecia' . $row['id_student_ankieta'] . '" id="ocena_zajecia' . $row['id_student_ankieta'] . '">5,0 - 4,5

                    <br/><br/> <br/><input class="button" type="submit" name="dodaj' . $row['id_student_ankieta'] . '" value="dodaj">

                    </form></div>';
        }

    echo'       </div>
            </div>
            <footer>
            </footer>
        </body>
    </html>';
    ?>

0 个答案:

没有答案