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

195
Views
How to format input in html using javascript

How to format input text on html, sample input: Hi hello

I like to display the input like this

'Hi','hello',

When I hit enter, single quote with a comma will automatically display.

Any suggestion? Thank you.

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

0

You can use split and join

const str = "Hi hello";
let output = '';
if(str)
     output = `'${str.split(" ").join("','")}',`;
 console.log(str);
about 4 years ago · Juan Pablo Isaza Report

0

The text is then formatted and returned to the input field. You only need an eventlistener, a function that converts the text.

const input = document.getElementById('watch');
input.addEventListener('keypress', function (e) {
    e.preventDefault();
    if (e.key === 'Enter') {
      input.value = input.value.split(' ').map(s => `'${s}'`).toString() + ',';
    }
  return false;
});
<form>
  <input type="text" value="Hi World" id="watch">  
</form>

about 4 years ago · Juan Pablo Isaza Report

0

const string = 'a b c'
console.log(string.split(' ').map(str => `'${str}'`).toString() + ',')

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!