how do i add the icons within the input fields not appended to the right, also the icon…
- User
how do i add the icons within the input fields not appended to the right, also the icon should be black with no outline: To mask the password and confirm password fields as stars (••••) and add an eye icon to toggle their visibility, follow these steps. You will need to modify the HTML to use
passwordtype input fields and add a button for the eye toggle. Also, we will use some JavaScript for the toggle functionality.Step 1: Modify the Password Fields in HTML
Change the type of your password fields from
type=""totype="password"and add a toggle button with an eye icon. If you are using FontAwesome for icons, you can use the eye icon classfa-eyefor the toggle button.<div class="form-group"> <legend>Password</legend> <div class="input-group"> <input type="password" name="exPass" id="passwordField" class="form-control" required="" value="<?php echo $selAccRow['exmne_password']; ?>"> <div class="input-group-append"> <button type="button" class="btn btn-outline-secondary toggle-password" toggle="#passwordField"><i class="fas fa-eye"></i></button> </div> </div> </div> <div class="form-group"> <legend>Confirm Password</legend> <div class="input-group"> <input type="password" name="exPass2" id="confirmPasswordField" class="form-control" required="" value="<?php echo $selAccRow['exmne_password']; ?>"> <div class="input-group-append"> <button type="button" class="btn btn-outline-secondary toggle-password" toggle="#confirmPasswordField"><i class="fas fa-eye"></i></button> </div> </div> </div>Step 2: Add JavaScript for Toggle Visibility Functionality
Below is a simple jQuery script that toggles the type attribute of the password fields between
passwordandtext, making it possible to show or hide the password. Make sure you include jQuery in your project for this to work.<script> $(document).ready(function() { // Listen for click on toggle-password button $(".toggle-password").click(function() { // Determine the input field and current type var input = $($(this).attr("toggle")); var inputType = input.attr("type") === "password" ? "text" : "password"; // Toggle the input field type attribute input.attr("type", inputType); // Toggle the icon of the button, assuming you have fa-eye-slash for the 'hide' state $(this).find('.fas').toggleClass("fa-eye fa-eye-slash"); }); }); </script>Additional Steps:
-
Make sure you have loaded the FontAwesome library if you haven't already, to use their eye icons (
fa-eyeandfa-eye-slash). You can add it to the<head>section of your HTML:
-
- Assistant
To incorporate the icon within the input field instead of appending it to the right, and ensuring the icon is black with no outline, you will need to slightly restructure your HTML and adjust your CSS. Here's how you can achieve this:
Step 1: Update your HTML Structure
You need to create a structure that allows the icon to appear inside the input field. This involves using a container for each input field, styled in such a way that it visually contains both the input and the icon.