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.
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>