Is there a way to create a textbox input that provides autocomplete/autosuggest but displays only the first match directly within the textbox instead of showing a list?

While I came across several autocomplete/autosuggest samples, none of them quite fit what I'm looking for. Instead of displaying a list below the textbox that requires clicking or selecting, I want to show the closest match inside the textbox itself as the user is typing. This way, they can easily tab or use another method to complete the entry.

I believe I have the logic in Javascript (using Vue JS) figured out, but I am struggling with how to actually display this suggestion inside the input. I envision the suggested text being slightly dimmer in color, similar to placeholder text, and getting overwritten as the user continues typing.

Does anyone have any suggestions on how to achieve this?

Answer №1

To position it securely, you can utilize absolute positioning with a low z-index.

<div class="container">
      <input v-model="value" @keyup.prevent="autofill"></input>
      <div class="suggested">
      {{suggested}}
      </div>
</div>

input {
  border: 4px solid #e3e3e3;
  padding:10px;
  width:100%;
}
.container {
  width:50%;
  margin: auto;
  position:relative;
}
.suggested {
  position:absolute;
  top:25px;
  left:25px;
  color:#e3e3e3;
  z-index:-1;
}

Here's a live demo for reference: https://codepen.io/ellisdod/pen/mdJayxo

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

"Navigate with ease using Material-UI's BottomNavigationItem and link

What is the best way to implement UI navigation using a React component? I am currently working with a <BottomNavigationItem /> component that renders as a <button>. How can I modify it to navigate to a specific URL? class FooterNavigation e ...

Laravel websocket notification causes Vue.js component to stop updating

I'm attempting to update the notification list in real-time, but the Vue component in view is not refreshing. Here's my current code: app.js require('./bootstrap'); window.Vue = require('vue'); Vue.component('notificati ...

Utilizing a debugger to set a stopping point within a Vue application

Just starting out with Vue and trying to implement a simple scoped breakpoint in my component. <template> <div class="date-picker"> <p>{{ date }}</p> </div> </template> <script> import moment from ' ...

Having trouble with my routes in Express Router - the page just won't load!

My backend is not functioning properly. The server is starting without any issues, but when I try to access http://localhost:5000/api/items, it just loads indefinitely. I am unsure of what I am doing wrong. Below is my server.js file: const express = requ ...

What is the best way to use jQuery to update the color of an SVG shape?

Hello everyone! I'm excited to be a part of this community and looking forward to contributing in the future. But first, I could really use some assistance with what seems like a simple task! My focus has always been on web design, particularly HTML ...

Create a roster of numbers that are multiples using a systematic approach

Is the following code a functional way to return multiples of 5? function Mul(start,array,Arr) { Arr[start]=array[start]*5; if(start>array.length-2){ return Arr; } return Mul(start+1,array,Arr); } var numbers =[1,2,3,4,5,6 ...

Nodemailer contact form malfunctioning

I've been working on setting up a contact form in React and utilizing nodemailer to send messages to my email, but I seem to be encountering some issues. I have a server.js file located in the main folder along with Mailer.js which contains the form c ...

Issue with Tooltipster plugin causing jQuery function not to trigger upon clicking the link within the tooltip

Recently, I've been experimenting with a jquery plugin called Tooltipster by inserting some HTML into the tip with an href link. The problem arises when I try to add a class to the href and fire a jquery function upon clicking it. No matter how much I ...

What is the syntax for implementing a nested for loop in JavaScript within this particular scenario?

var entries = [ { "item": "something", "steps": [{ "node": {"name": "test0"}, "status": {"name": "test"}, "time": {"name": "test"} },{ "node": {"name": "test1"}, ...

Generate a dynamic vertical line that glides smoothly over the webpage, gradually shifting from one end to the other within a set duration using javascript

I have designed a calendar timeline using html. My goal is to implement a vertical line that moves from left to right as time progresses, overlaying all other html elements. This functionality is similar to Google Calendar's way of indicating the curr ...

What drawbacks should be considered when utilizing meteor.js for development?

After viewing the meteor.js screencast, I was truly impressed by its seamless web application development capabilities, especially in terms of live updates and database synchronization. However, I am curious about its scalability once the website goes live ...

Using Leaflet JS to add custom external controls to your map

Is there a way to implement external controls for zooming in on an image? I've searched through the documentation, but haven't been able to find a clear solution. HTML: <div id="image-map"></div> <button id="plus">+</butto ...

The presence of Firefox Marionette has been identified by hCaptcha

Whenever I go on indeed.com using the firefox web driver in Marionette mode, I keep encountering an hCaptcha popup. In an attempt to avoid this, I experimented with a user script that alters the navigator.webdriver getter to return false right at the sta ...

Vue.js and Firestore will only update variables that do not have empty string values

Modify the variables that are not empty strings const state = reactive({ birthNumber: '', phoneNumber: '', DoctorName: '', DoctorPhone: '', }) db.collection(state.user.uid).doc( ...

Vue.js App encounters Recaptcha contact form 7 with a status of "spam"

I recently developed a Vue.js application that operates on a subdomain within the same main domain as my WordPress site. To submit a form to the contact form 7 rest API, I utilized the axios package. However, every time I submit the form, I receive a respo ...

Implementing a dual hover effect on a Div element

I am working with HTML code that includes an image and text <div class="subcontainer1"> <img src="a.png" alt="" class="imgcolumn"> <h3 class="header3">Hello</h3> </div> This setup places the content above the image. ...

To enhance the MUI v5 table row, simply apply a border when the mouse hovers

After working on creating a table with Material UI v5, I encountered an issue where I wanted to add a blue border to the table row when the mouse pointer hovered over it. I attempted several methods and did thorough research, but unfortunately, I was unab ...

Guide on how to automatically log out a user at a designated time

I am working on a basic application with login functionality using webforms, and I want to automatically log out the user at a specific time for updates. For example, at 13:30, I need to logout the user from the website and redirect them to the login page. ...

Trouble with the onload function in onMounted vue3

For my vue3 component, I need to load certain scripts. Here is what I am currently implementing: <script setup> import { onMounted } from 'vue' function createElement (el, url, type) { const script = document.createElement(el) if (type ...

Determine the exact width of text without rounding in Javascript

I'm facing an issue with a div element that I'm manipulating using Javascript to change its position. The problem is that it's rounding off incorrectly. #hi{ background-color: blue; width: 2px; height: 10px; position: absolu ...