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

151
Views
html change/replace string after input

function convertUnits(obj) {
  if($(obj).is(":checked")){
    $(obj).after(' "');
  }else{
    $(obj).after(' mm');
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <input type='checkbox' id='units' onchange="convertUnits(this)"/>
    </td>
  </tr>
  <tr>
</table>

I'm trying to change/replace text after a text input depending on which radio button is chosen.

I can add text but it doesn't replace it...

I'm using this code to add the text... convInputs is an array of all the inputs I want to add text to the end of the input. Depending on the checkbox selected it's either ' /', ' "' or ' mm' like in the example text.

Right now when I switch checkbox the text is just added together and not replaced with the new text... ie: / " mm.

[https://jsfiddle.net/frankn/c6mjvLxd/19/][1]

edit: added jsfiddle with a simplified code example of my actual code and what's happening.

edit #2: as suggested I added code snippet here.

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

0

Well after a messy question and some help and suggections... here's what I came up with...

function convertUnits(obj) {
  if($(obj).is(":checked")){
    $(obj).next().remove()
    $(obj).after("<label> test</label>")
  }else{
    $(obj).next().remove()
    $(obj).after("<label> new</label>")
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tr>
    <td>
      <input type='checkbox' id='units' onchange="convertUnits(this)"/>

    </td>
  </tr>
  <tr>
</table>

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!