Showing posts with label jquery. Show all posts
Showing posts with label jquery. Show all posts

Saturday, June 26, 2021

restrict user to enter only alphabates

 <-- KIRTISHIL PATIL-->

 <!doctype html>

<html lang="en">

<head>

    <title>Title</title>

    <!-- Required meta tags -->

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <style>

        .small {

            color: #b0aeb8;

            text-transform: capitalize;

            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;

        }

        .small-err {

            color: #ff2525;

            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;

        }

        .input-err,

        .input-err:focus {

            border: 1px solid #ff2525;

            box-shadow: 0 0 0 0.2rem #ff00003b;

        }

    </style>

</head>

<body>

    <h1>User unable to enter alphabets strict to numbers only</h1>

    <small class="small limiterr mt-2">Limit</small>

    <div class="form-group">

        <input type="text" class="form-control" name="" min="1" max="700" maxlength="3" onkeyup="isNumber(this.value, this)" id="limit" aria-describedby="helpId" placeholder="Enter Value" value="500" />

    </div>

    <!-- Optional JavaScript -->

    <!-- jQuery first, then Popper.js, then Bootstrap JS -->

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

    <script>

        function isNumber(val, elem) {

            val = val.trim();

            var reg = /^\d+$/;

            if (reg.test(val)) {

                //normal css

                $("#limit").removeClass("input-err");

                $(".limiterr").removeClass("small-err");

            } else {

                //red css

                $("#limit").addClass("input-err");

                $(".limiterr").addClass("small-err");

                $(elem).val("");

            }

        }

    </script>

</body>

</html>

input box value trim and show error

 <-- KIRTISHIL PATIL-->

 <!doctype html>

<html lang="en">

<head>

    <title>Title</title>

    <!-- Required meta tags -->

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <style>

        .small {

            color: #b0aeb8;

            text-transform: capitalize;

            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;

        }

        .small-err {

            color: #ff2525;

            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;

        }

        .input-err,

        .input-err:focus {

            border: 1px solid #ff2525;

            box-shadow: 0 0 0 0.2rem #ff00003b;

        }

    </style>

</head>

<body>

    <div class="container">

        <h1>Input box trim whitespaces if value="" display error in red</h1>

        <small class="small titleerr mb-4"> Enter title </small>

        <input type="text" class="form-control" name="" id="title" onkeyup="onKeyUpTitle(this.value,this)" aria-describedby="helpId" maxlength="20" placeholder="Enter title" />

    </div>

    <!-- Optional JavaScript -->

    <!-- jQuery first, then Popper.js, then Bootstrap JS -->

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

    <script>

        function onKeyUpTitle(val, e) {

            val = val.trim();

            if (val == "") {

                $("#title").addClass("input-err");

                $(".titleerr").addClass("small-err");

            } else {

                $("#title").removeClass("input-err");

                $(".titleerr").removeClass("small-err");

            }

        }

    </script>

</body>

</html>

toastr - easiest way to display notifications

 <-- KIRTISHIL PATIL-->

<!doctype html>

<html lang="en">

<head>

    <title>Toastr Example</title>

    <!-- Required meta tags -->

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- jQuery js -->

    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

    <!-- BS js -->

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>

    <!-- toastr files -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js" type="text/javascript"></script>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">

    </link>

</head>

<body>

    <h1>This is toastr(notifications)</h1>

    <script>

        function raiseToasterMessage(type, msg, title) {

            toastr.options = {

                closeButton: false,

                newestOnTop: true,

                positionClass: "toast-bottom-right",

                preventDuplicates: false,

                onclick: null,

            };

            toastr[type](msg, title);

        }

        var a = 11;

        for (let i = 0; i < a; i++) {

            if (i == 1) {

                raiseToasterMessage("warning", "This is warning", "warning");

            } else if (i == 2) {

                raiseToasterMessage("error", "This is error", "error");

            } else if (i == 3) {

                raiseToasterMessage("success", "This is success", "success");

            }

            else if(i==4)

            {

                raiseToasterMessage("info", "This is info", "info");

            }

        }

    </script>

</body>

</html> 

Jquery basic events

 <-- KIRTISHIL PATIL-->

 <!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>JQuery Basic</title>

    <link rel="stylesheet" href="style.css">

    <script src="https://code.jquery.com/jquery-3.5.1.min.js" 

    integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" 

    crossorigin="anonymous"></script>

</head>

<body>

    <h1>JQuery Basic</h1>

    <h3>Kirtishil Patil</h3>

    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Architecto, modi sed, enim temporibus nisi ducimus alias, exercitationem provident ipsum sit esse voluptates! Asperiores, repudiandae. Maxime sit laborum et inventore fugiat!</p>

    <button id="but3">fadeOut</button>

    <button id="but4">fadeIn</button>

    <div class="imgs">

        <img src="./2.jpg" alt="error">

    </div>

    <button id="but1">addClass</button>

   <br>

    <input type="text" id="name" value="" size="10">

    <button id="but2">Submit</button>

    <br>

    <button id="slide">Slide</button>

    <div id="one" style="background-color: red; width: 50px; height: 50px;">

    </div>

    <br>

   <script> 

   /*

        datepicker()

        draggable()

        droppable()

   */

        $("img").attr("border","5px solid black")

        $(document).ready(function(){

            $("#but2").click(function(){

                alert("Name: "+ $("#name").val());

            })

            $("#but1").click(function(){

                $("img").addClass("styleClass");

            })

            $("img").click(function(){

                $(this).hide();

            })

            $("input").on("keypress", function(){

                $("p").hide();

            })

            $("#but3").click(function(){

                $("img").fadeOut("slow"); 

            })

            $("#but4").click(function(){

                $("img").fadeIn("fast"); 

            })

            $("#slide").on("click", function(){

                $("#one").slideUp("slow");

            })

            $("#slide").on("click", function(){

                $("#one").slideDown("fast");

            })

        })

    </script>

    <style>

        .styleClass{

            border: 5px solid red;

        }     

    </style>

</body>

</html>

Kirtishil Patil