Posts

Showing posts with the label JavaScript

How TO - Toggle Hide and Show an Element | CodeLSC

How TO - Toggle Hide and Show an Element | CodeLSC

Load-on-Demand and Lazy Loading in Custom Dropdowns | CodeLSC

Load-on-Demand and Lazy Loading | CodeLSC

How to Prevent the Keypress Event in JavaScript | CodeLSC

Image
The keypress event is triggered when a user presses a key on their keyboard. This event can be used to do things like restrict the input that a user can enter, or to show an error message if the user enters an invalid character.   To prevent the keypress event, you can use the preventDefault() method. This method is called on the event object that is passed to the event listener function. The following code shows how to prevent the keypress event from being triggered when a user presses a letter key on the name input field: const nameInput = document . getElementById ( 'fname' ); nameInput. addEventListener ( 'keypress' , function ( event ) { const allowedCharacters = /^[a-zA-Z]+$/ ; if (!allowedCharacters. test (event. key )) { event. preventDefault (); } });   In this code, the allowedCharacters regular expression is used to check if the key that the user pressed is a letter. If the key is not a letter, the prev

How to Bind Remote Data to Dropdownlist using JavaScript | CodeLSC

Image
How to Bind Remote Data to Dropdownlist using JavaScript | CodeLSC   Implementing a Dropdownlist with Remote Data using jQuery AJAX Dropdownlists are a common UI element used in web applications to allow users to select options from a list. In some cases, we may need to populate a dropdownlist with data retrieved from a remote data source. This tutorial will show you how to implement a dropdownlist with remote data using JavaScript and jQuery AJAX. Requirements: jQuery library (version 3.6.0 or above) A remote data source in JSON format (for this tutorial, we will be using the JSONPlaceholder API)   HTML: The HTML code for our dropdownlist is very simple. We have a select element with an id of "postsDropdown" and one default option with the value "null". <select id="postsDropdown"> <option class="e-popup" value="null">Sele

Show/Hide Password Toggle with JavaScript | With Source Code | CodeLSC

Image
Learn how to create a show/hide password toggle using JavaScript and Font Awesome icons Introduction: Have you ever needed to create a password input field that allows the user to toggle the visibility of their password? With JavaScript and Font Awesome icons, it's easy to create a show/hide password toggle that makes your password input fields more user-friendly. In this tutorial, we'll walk through the steps of creating a show/hide password toggle that you can use in your own web projects. Preview: Step 1: HTML Markup First, let's create the HTML markup for the password input field and the eye icon that will serve as our toggle button. Here's the code for the form:      < center >        <form   style = "width: 350px; margin: auto" >          <h2> CodeLSC </h2>          <div   class = "input-icons" >            <i   class = "fa fa-user icon" >   </i>            &l