validate file multiple show message only required using ajax

validate file multiple show message only required using ajax


Validate file multiple show message only required using ajax



Step: index.html

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Validate form</title>
    <!-- library bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <!-- library js validate -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.js"></script>
    <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.js"></script>
    
    <!-- style css form color -->
    <style>
        .error {
            color: red;
            border-color: red;
        }
        .panel-primary {
            border-color: #33cabb !important;
        }
        .btn-primary {
            background-color: linear-gradient(315deg, #20bf55 0%, #01baef 74%);
        }
        .panel-primary .btn{
            border-radius: 1px !important;
            border-color: #33cabb !important;
        }
        .panel-primary>.panel-heading {
            color: #fff !important;
            background-color: linear-gradient(315deg, #20bf55 0%, #01baef 74%);
            border-color: #33cabb !important;
        }
    </style>

</head>
<body>
    <div class="container">
        <div class="row">
            <h1>soengsouy.com</h1>
            <div class="panel panel-primary">
                <div class="panel-heading">
                    Create Employee 
                </div>
                <div class="panel-body">
                    

                    <form class="form-horizontal" id="validate">
                        <div class="form-group">
                            <label class="col-md-4 control-label" for="textinput"><span id="message_error"></span></label>
                            <div class="col-md-4">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-4 control-label" for="textinput">Employee Name </label>
                            <div class="col-md-4">
                                <input  type="text" id="name" name="name" placeholder="Enter Name" class="netEmp form-control input-md" required>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="col-md-4 control-label" for="textinput">Phone number </label>
                            <div class="col-md-4">
                                <input id="phoneNumber" name="phoneNumber" type="text" placeholder="Enter phone number" class="netEmp form-control input-md" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-4 control-label" for="textinput">Salary </label>
                            <div class="col-md-4">
                                <input type="text" id="salary" name="salary" placeholder="Enter Salary" class="netEmp form-control input-md" required>
                            </div>
                        </div>

                        <br />
                        <div id="employeeList"></div>
                        <div class="form-group">
                            <label class="col-md-4 control-label" for="button1id"></label>
                            <div class="col-md-8">
                                <button id="btnSubmit" type="submit" name="btnSubmit" class="btn btn-primary">Submit</button>
                                <input id="btnReset" type="reset" name="btnReset" class="btn btn-info" value="Reset">
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
    <!-- alert blink text -->
    <script>
        function blink_text()
        {
            $('#message_error').fadeOut(700);
            $('#message_error').fadeIn(700);
        }
        setInterval(blink_text,1000);
    </script>
    <!-- script validate form -->
    <script>
        $('#validate').validate({
            reles: {
                name: {
                    required: true,
                },
                phoneNumber: {
                    required:true,
                },
                salary: {
                    required:true,
                }
            },
            messages: {
                name : "Please input file*",
                phoneNumber : "Please input file*",
                salary : "Please input file*",
            },
            errorPlacement: function (error, element)
            {
                if(element.attr("name") == "name" || element.attr("name") =="phoneNumber" || element.attr("name") =="salary")
                {
                    $('#message_error').empty();error.appendTo('#message_error')
                }
                else
                {
                    error.insertAfter(element);
                }
            }

        });
    </script>

</body>
</html>
Reactions

Post a Comment

0 Comments

close