Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
How to prepopulate a search bar and let user change value?

I have a simple search bar and I want to pre-populate it with some data. I've tried using value but it doesn't let the user change the value in the search bar afterward.

<input type="search" class="navBarSearchForm3 form-control rounded searchterm2" placeholder="search term" value={comparelinks}></input>

I'd like the searchbar to already have a value and let the user be able to change it. Do I need some JS for it or can it be done with just HTML?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are missing the handle of the change. So, you need to edit the value when the user changes something on the input it would be like:

In this case, I'd use React Hooks (useState) to be able to set one default value and being able to change it.

And finally, use that seCompareLinks when user onChange in the input.

You can see it working here: https://codesandbox.io/s/practical-dewdney-wj7j2?file=/src/App.js:0-543

import React from 'react'; 
import "./styles.css";

export default function App() {
  const [comparelinks, setComparelinks] = React.useState('default value');

  const handleChange = (e) => {
    setComparelinks(e.target.value);
  }

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
      <input type="search" class="navBarSearchForm3 form-control rounded searchterm2" placeholder="search term" value={comparelinks} onChange={handleChange}></input>

    </div>
  );
}
about 4 years ago · Juan Pablo Isaza Report

0

You have to handle the update of the input as well, considering you use hooks:

const [comparelinks, setCompareLinks] = useState()

const handleChange = (event) => {
  setCompareLinks(event.target.value)
}

<input type="search" class="navBarSearchForm3 form-control rounded searchterm2" placeholder="search term" value={comparelinks} onChange={handleChange}></input>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!