In this example, I created an input form and compared it with custom string using jquery val() function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Code4Example.com</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script> </head> <body> <div class="container"> <form> <div class="form-group"> <label for="string1">Enter String:</label> <input type="text" class="form-control" id="string1"> </div> <div class="alert alert-success" id="result"> </div> <button type="button" id="compareBtn" class="btn btn-primary">Compare</button> </form> </div> <script> $("#compareBtn").click(function(){ var customString="Hello"; if(customString==$("#string1").val()) $("#result").text("'"+customString+"' is Equel to '"+$("#string1").val()+"'"); else $("#result").text("'"+customString+"' is Not Equel to '"+$("#string1").val()+"'"); }); </script> </body> </html> |
Output: