How can I remove repetition in this code?

"duplicate code" refactoring
code duplication detection
duplicate code fragment
how to refactor code
extract method refactoring
java program to remove duplicates from string array
c# refactor duplicate code
refactor common code

I'm just calling a function highlightInput(this) which is just changing colors for selected input. I think there might be a better way to avoid repetition. Any ideas?

HTML file

<div class="form-group">
    <label for="your_name">Your name:</label>
    <input type="text" class="form-control" name="your_name" onfocus="highlightInput(this);">
</div>
<div class="form-group">
    <label for="email">Email:</label>
    <input type="email" class="form-control" name="email"onfocus="highlightInput(this);">
</div>
<div class="form-group">
    <label for="title">Event title:</label>
    <input type="text" class="form-control" name="title"onfocus="highlightInput(this);">
</div>
<div class="form-group">
    <label for="location">Event location:</label>
    <input type="text" class="form-control" name="location"onfocus="highlightInput(this);">
</div>


How highlightInput looks like:

var Color = {
    inputColor:function (color, self){
        $(self).css('backgroundColor', color);
    }
}

function highlightInput(self){
    Color.inputColor('lightyellow', self);
    $(self).blur(function(){
        Color.inputColor('white', self);
    });
}

Get rid of the jQuery and do it with CSS.

input.form-control:focus {
 background-color: lightyellow;
}
<input type="text" class="form-control">

Python Remove Duplicates from List, How do you remove repeats from a list in Python? Stack Overflow Public questions and answers Teams Private questions and answers for your team Enterprise Private self-hosted questions and answers for your enterprise

You can use jQuery selector to addEventListener.

Add the following to the <head> tag.

<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>


JavaScript

$('input.form-control').focus(function(e){
   highlightInput(this);
});

Duplicate code, Sounds like a case for the "Strategy Pattern". class A extends ApiClass { private ClassContainingDupMethod strategy; } class N extends  Remove repetition from cypress tests. Ask Question In the above code you can see I have to use isRollDisabled in each even when its not required in the test

$('input.form-control').blur(function() {
  this.style.backgroundColor = 'white';
});

$('input.form-control').focus(function() {
  this.style.backgroundColor = 'lightyellow';
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
  <label for="your_name">Your name:</label>
  <input type="text" class="form-control" name="your_name">
</div>
<div class="form-group">
  <label for="email">Email:</label>
  <input type="email" class="form-control" name="email">
</div>
<div class="form-group">
  <label for="title">Event title:</label>
  <input type="text" class="form-control" name="title">
</div>
<div class="form-group">
  <label for="location">Event location:</label>
  <input type="text" class="form-control" name="location">
</div>

remove duplicate code in java, Given a sorted array, the task is to remove the duplicate elements from the array. Examples: Simple C++ program to remove duplicates Driver code. int main  Thanks for contributing an answer to Code Review Stack Exchange! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. Use MathJax to format equations.

Duplicate Code, use set in c++ stl which implements a self balancing Binary Search Tree. filter_none. edit close. play_arrow. link brightness_4 code  What I want to have is to remove the repetition, but maintain the original order: ['maier', 'tapa pure', 'embega'] I cant use v[:3] because the repetitions length is variable. How can I do it? Thanks in advance.

Remove duplicates from sorted array, Removing duplicate code. To remove the duplication, you can change the BookRentals class ("refactor" it): public class BookRentals { private Vector rentals​;. 1) Sort the elements. 2) Now in a loop, remove duplicates by comparing the current character with previous character. 3) Remove extra characters at the end of the resultant string. Example: Input string: geeksforgeeks 1) Sort the characters eeeefggkkorss 2) Remove duplicates efgkorskkorss 3) Remove extra characters efgkors

Remove duplicates from a given string, If you like to have a function where you can send your lists, and get them back without duplicates, you can create a function and insert the code from the example  Let us go even further and consider a 5-repetition code. In this case, for both information bits 0 and 1, we will have the following codewords: 00000 and 11111. As practice, you can show that this will improve our detection and correcting capabilities and give us a Cc which equals 2 and a Cd which equals 4.

Comments
  • What is version of jQuery you're using?
  • Is there any specific reason to use JavaScript/jQuery, when it can be implemented better with CSS?
  • version: 1.12.4 && No specific reason.. Just I don't have enough knowledge on CSS
  • You should include the <script> necessary to use jQuery. I assume OP has no idea what jQuery is. anyways +1
  • @CalebGoodman It's tagged with jQuery. Also, OP's code contains jQuery, doesn't it? So it's safe to assume that he knows about it.
  • Ignore my ignorance xD