Field where tags are generated by user input

I want to incorporate an input field on my website where users can list their skills. These skills should be displayed individually as separate elements on the front end of the site. The desired format for users to input their skills is as follows:

skill 1, skill 2, skill 3

When displayed on the front end, it should appear like this:

[Skill 1] [Skill 2] [Skill 3].

The use of a comma will delineate each skill
and CSS styling will be applied to each individual skill.

I have experimented with various methods but none have achieved the result I envisioned. Any assistance in achieving this layout would be greatly appreciated.

Thank you

Answer №1

Unfortunately, without JavaScript enabled (make sure to add the appropriate tags to your Question), it is not possible to implement this feature. This particular example allows you to continuously input your skills, and by pressing either the comma key or the Enter key, you can separate them.

jQuery(function($) {

  $('#tags input').on('focusout', function() {
    var txt = this.value.replace(/[^a-zA-Z0-9\+\-\.\#]/g, ''); // these are the allowed characters
    if (txt) $(this).before('<span class="tag">' + txt + '</span>');
    this.value = "";
    this.focus();
  }).on('keyup', function(e) {
    // comma|enter (add more keyCodes delimited with | pipe)
    if (/(188|13)/.test(e.which)) $(this).trigger('focusout');
  });

  $('#tags').on('click', '.tag', function() {
    if (confirm("Are you sure you want to delete this tag?")) $(this).remove();
  });

});
#tags {
  float: left;
  border: 1px solid #ccc;
  padding: 4px;
  font-family: Arial;
}

#tags span.tag {
  cursor: pointer;
  display: block;
  float: left;
  color: #555;
  background: #add;
  padding: 5px 10px;
  padding-right: 30px;
  margin: 4px;
}

#tags span.tag:hover {
  opacity: 0.7;
}

#tags span.tag:after {
  position: absolute;
  content: "×";
  border: 1px solid;
  border-radius: 10px;
  padding: 0 4px;
  margin: 3px 0 10px 7px;
  font-size: 10px;
}

#tags input {
  background: #eee;
  border: 0;
  margin: 4px;
  padding: 7px;
  width: auto;
}
Add a skill and hit [,] or [Tab] or [Enter]<br><br>

<div id="tags">
  <span class="tag">Photoshop</span>
  <span class="tag">Illustrator</span>
  <input type="text" value="" placeholder="Add a skill" />
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

Answer №2

How about giving this a try?

It's an innovative tags editor jquery plugin that resembles stackoverflow tags. I find it quite impressive. However, you may need to make some customizations to tailor it to your specific needs.

Answer №3

If you are incorporating client side scripting, you can utilize the jQuery function split() to separate a value with comma(',') into an array, then attach a CSS class to each element in the array and show it.

var data = "skill 1, skill 2, skill 3";
data_array = data.split(",");

You can retrieve the elements using data_array[0], data_array[1], and data_array[2].

Add or append these values to input fields or HTML elements using .css( "color", "red" )

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

Personalizing the Twitter Bootstrap grid layout to fit your needs

I am currently attempting to adjust the number of columns in the standard Bootstrap grid layout from 12 to 8. After reviewing the Bootstrap documentation, I understand that this requires modifying the @gridColumns variable and making adjustments in the res ...

How to style a MenuButton's ContextMenu individually with CSS in JavaFX

I've been trying to figure out how to adjust the coordinates of a MenuButton's Context Menu using CSS, but I haven't had any luck so far. I attempted to use the "top" property in CSS, but it didn't work. I also tried using padding, but ...

Search for text within the nearest <p> tag using HTML and jQuery

My table contains different td elements with the same ID, as shown in this foreach loop: <td class="AMLLeft" style="display:inline-block; !important">ID: <p class="important">${item.id}</p> </td> <td align="right" nowrap="tr ...

Simple CSS3 Features for Seamless Browser Compatibility

Is there a more efficient way to add box-shadow to an HTML element? Currently, I have to include the following code: box-shadow: 2px 2px 3px #969696;<br> -moz-box-shadow: 2px 2px 3px #969696;<br> -webkit-box-shadow: 2px 2px 3px #969696; filte ...

Experiencing the appearance of a scroll bar upon adjusting the padding of mat-dialog-container to 0

One issue I encountered was with a Dialog Box that has a blue top Bar using the mat-dialog class and styling from the mat-dialog-container. The default style of the mat-dialog-container was causing some problems before, but I managed to solve it by creatin ...

Troubleshooting error in WordPress: Changing innerHTML of dynamically created divs using JavaScript. Issue: 'Unable to set property innerHTMl of null'

I am struggling to modify the innerHTML of a "View cart" button using a dynamically generated div class on my Wordpress/Woocommerce site. In a previous inquiry, I was informed (thanks to Mike :) ) that since JavaScript is an onload event, the class changes ...

What is the best way to incorporate jQuery and its plugins into a Vue component?

Is there a way to include jQuery plugins in a Vue application and use them inside the mounted hook? I know that jQuery can be imported via "import" inside a component (in the export default object) and is used in the life-cycle hook called "mounted." Howev ...

What is the process for using the scrollIntoView function on an svg element like a rectangle?

I have a graph panel with an SVG. The nodes in the SVG are listed in a separate panel. I would like for when a node is clicked in the node list, the SVG will scroll to that specific node. Each node is represented by a rectangle shape. However, I noticed th ...

Discovering the full URL of an image tag

Currently, in my web scraping project using Node.js and cheerio, I've encountered an issue where I'm unable to extract the absolute URL of an img tag. Below is the code snippet I am working with: $('.images').each(function () { cons ...

Responsive slide displays a unique number of items per slide depending

I created a logo slider using Bootstrap, similar to the one showcased here: http://jsfiddle.net/juddlyon/Q2TYv/10/. Currently, each slide in the slider displays 4 logos. I would like to make it responsive so that on smaller screens, only 2 logos are shown ...

Is it possible to execute PHP without using Ajax when clicking on a Font Awesome icon?

So, besides using Ajax, is there another solution to achieve the same result? Can a font-awesome icon be turned into a button without Ajax? In case you're unfamiliar with what I mean by a font-awesome icon, here's an example: <i id="like1" on ...

How to successfully pass a string variable from JavaScript to PHP using Ajax

I have been using this piece of JavaScript: <script> $( document ).ready(function() { var namer = sessionStorage.getItem("namer"); $.ajax({ type: "POST", url: "Antibiotics2.php", data: { ' ...

CSS for decorating an image with a border and transparent background

Struggling to add a border while converting a PSD to HTML? Is it possible to apply a border to an image with a transparent background? For instance, let's consider the following image: Imagine wanting to place a border around the caret in the image l ...

Is it more suitable for the response logic to be implemented within the saga or the reducer?

Consider this scenario: export function* incrementAsync(action) { try { const res = yield call(Api.signin.create, action.payload); yield put({ type: USER_SIGN_IN_FETCH_SUCCESS, payload: res.data.auth }); } catch (e) { yie ...

Error: The React component throws a TypeError because it is unable to read the property 'map' from an undefined source

I encountered the following error TypeError: Cannot read property 'map' of undefined at ListItemFactory.ts:84:57 at The specific line where the error occurs is: return announcementitems=json.value.map((v,i)=>( To provide mor ...

How can you modify an existing animation style upon hovering?

Take a look at the code snippet below. As you hover over an item, you'll notice the background color changes, but the transform: translateY(-5px) property is not being applied. The transform effect on hover only works when the .list-item animation is ...

Ways to sort data based on dropdown selection in MVC Razor

I am facing a requirement where I have a list of vendors that are displayed on the page load. Additionally, there is a dropdown menu which acts as a filter for these vendor records when its value changes. This is my view: <div class="half-left"> ...

Has the Field Validity Been Verified and Are all Fields Completed Prior to Submitting?

I have made changes to this question and am seeking clarification. In my project, I have a form with multiple fields, some of which require regex validation. Currently, I have a function that checks if all fields are filled before enabling the submit butto ...

Employing a pair of interdependent v-select components to prevent any duplicate entries

I am currently working with two v-select boxes that share similar data. In my scenario, I extract attachments from an email and load them into an array. The issue I encountered is that the first select box should only allow the selection of one document, w ...

Optimal approach for customizing the appearance of child components based on the parent component

I'm curious about the optimal method for styling child components based on their parent component. For instance, I want to design a list component that can be utilized in both a dropdown popup and a toolbar, each with its own unique style. There are ...