Can Bootstrap be used to emphasize changed input text?

Is there a feature or customizable tool that can visually highlight input elements when they have been changed? This could involve applying a distinguishing visual cue, such as an orange border, to any input that no longer contains its default value. To reset all inputs to their original state as "unmodified," a JavaScript function (triggered by clicking on the "Save Changes" button) could be utilized.

Answer №1

To automatically add a class to input elements when their values change, you can attach a "change" event listener to each input element.


(function() {
  var inputs = document.querySelectorAll("input");

  for (var i = 0; i < inputs.length; i++) {
    var initialValue = inputs[i].value;

    inputs[i].addEventListener("change", function() {
      if (initialValue !== this.value) {
        this.classList.add("changed");
      } else {
        this.classList.remove("changed");
      }
    });
  }
})();
.changed {
  background-color: gold;
}
<form>
  <input type="text" value="Initial Value">
  <input type="text" value="Initial Value">
  <button type="submit">
    Save Changes
  </button>
</form>


If you wish to highlight the changed inputs after form submission, you can use the "changed" class as a selector and add another class with the desired styling.

Answer №2

If you're looking to incorporate AngularJS into your project, consider the following example:

<!DOCTYPE html>
<html lang="en">
<style>
    .red {
        color:red;
    }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="formCtrl">
  <form novalidate>
    First Name:<br>
    <input ng-change="myFunc()" type="text" ng-model="user.firstName" id="change">
  </form>
  <p>The input field has changed {{count}} times.</p>
  <p>form = {{user}}</p>
  <p>master = {{master}}</p>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
    $scope.master = {firstName:"John"};
    $scope.reset = function() {
        $scope.user = angular.copy($scope.master);
    };
    $scope.count = 0;
    $scope.myFunc = function() {
        $scope.count++;
        document.getElementById("change").className += " red";
    };
    $scope.reset();
});

</script>

</body>
</html>

For a live demonstration of this code snippet, access the provided JSFiddle link:https://jsfiddle.net/jve3x6Lk/1/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Splitting an array into multiple arrays with distinct names: A step-by-step guide

I have a data set that looks like this: [A,1,0,1,0,1,B,1,0,0,1,A,1]. I want to divide this array into smaller arrays. Each division will occur at the positions where "A" or "B" is found in the original array. The new arrays should be named with the prefix ...

Is there a way to transfer the chosen maximum and minimum price values to a JavaScript function within a select tag in HTML?

I have a search form that includes select options with two values. However, I want to have two select options for both the Max and Min price values. <input type="hidden" id="budget_min" name="filter_budget_min" value="0" /> <select onchange="upda ...

manipulating child element's innerHTML with javascript

Is there a way to change my icon from expand_more to expand_less in the code below? <li class="dropdown-bt" onclick="dropdown('content');"> <a>dropdown-content <i class="material-icons">expand_more</i></a> </ ...

If TextBoxes overlap, the one that is defined earlier in the ASPX file cannot be clicked on

Managing the visibility of multiple controls can be tricky, especially when they have overlapping coordinates. Take for example two TextBoxes, txtName and txtEmail, positioned at the same x/y coordinates: <div style="position: absolute; top: 55px; ...

Is there a way to remove a checkbox node that has already been generated?

I've been working on creating a to-do list, and I've run into an issue with deleting the checkbox once the task is complete. I attempted to create a function within the main function containing an if/else statement, but it didn't seem to wo ...

Browsing the web with Internet Explorer and uploading images

I am facing an issue with a large form that contains over 100 submit buttons. The code I am currently using is: <input type='image' src='../images/add.png' name='FormDuplicate' value='" . $resInvoices['iProjectID ...

Uh-oh! An unexpected type error occurred. It seems that the property 'paginator' cannot be set

I am developing a responsive table using Angular Material. To guide me, I found this helpful example here. Here is the progress I have made so far: HTML <mat-form-field> <input matInput (keyup)="applyFilter($event.target.value)" placeholder ...

Incorporating ajax and jquery into html: Step-by-step guide

Previously, I inquired about implementing a show/hide functionality for a div that only renders when a specific link is clicked. (View the original question) Following some advice, I was provided with jQuery and AJAX code to achieve this: function unhide() ...

Do mouse users prefer larger buttons on RWD sites for a better experience?

Not entirely certain if this platform is the most suitable for posing this query, so if warranted, please close it and recommend a more appropriate venue for such inquiries. In the realm of responsive web design (RWD) today, it is common practice for webs ...

The particles.js with absolute positioning is currently overlapping my div with relative positioning

Visit this link <div class="outer-container"> <div id="particles-js"> <div class="your-content"> <article id="3" class="bg-dusk transition md:group-hover:opacity-50 md:hover:opacity-important md:hov ...

Transfer data to ASP.NET MVC using AJAX and FormData

I am working with a simple model: public class MyModel { public string Description { get; set; } public HttpPostedFileBase File {get; set; } } and I have an MVC action for uploading data: [HttpPost] public ActionResult Upload(List<MyModel> d ...

"Adjusting the font size in a blogger's photo caption: A quick guide

I recently switched templates for my blog and I'm having trouble adjusting the size of the caption text under the photos. The template I'm currently using is called Awesome Inc. If you need more information, you can visit my blog here: https:// ...

The Ray Intersect function in THREE.js encounters issues when a div element is introduced

I have encountered an issue with my Three.js script. It works perfectly fine when there is only one target div on the page holding renderer.domElement. However, when I add another div with fixed height and width above the target div, the ray.intersectObjec ...

Two interactive dropdown menus featuring custom data attributes, each influencing the options available in the other

Looking to create interactive select boxes based on the data attribute values? This is the code I currently have: HTML <select id="hours" onchange="giveSelection()"> <option value="somethingA" data-option="1">optionA</option> <o ...

Automatically updating multiple divs using Jquery for a seamless user experience

I'm currently designing a dashboard for a large display at my workplace. I've successfully set up one div to automatically refresh a PHP request page, but I'm struggling to figure out how to apply this function to another div for a different ...

Ensure that a tiny image measuring 1*1 pixel just before the closing </body> tag does not generate unwanted margin

Take a look at this demonstration Even though I have set the <body> to have no margins whatsoever, a 1*1 image at the bottom of the page is causing a significant margin. Adding or removing the current CSS reset does not resolve the issue. What cou ...

Image transformed by hovering effect

I've been attempting to add a hover effect to the images in my WordPress theme. The images are displayed in a grid format, created by the featured image on the posts. The grid layout is controlled within content.php <?php /** * controls main gri ...

Changing the color of Material UI pagination: a step-by-step guide

I have integrated Material UI to create a pagination bar for my website. While everything is functioning properly, I am looking to personalize the appearance. After reviewing their documentation, I tried implementing a theme but encountered an issue with c ...

New programmer seeking to apply a dim effect to the entire photo while also adding a highlight when the image is hovered over

I am looking to add a special effect to my photos where they appear dimmed but highlighted when hovered over. Any guidance on how to achieve this would be greatly appreciated! The image is contained within a flexbox div that also contains a clickable lin ...

Adjusting the height of a card in Reactstrap

I am currently exploring Reactstrap and aiming to ensure a specific Card adjusts according to the size of the window by setting its aspect ratio using percentages rather than pixels. Interestingly, while adjusting the width works as desired, I'm faci ...