How could I delete the last character from an input in JQuery? For example, onclick of something, it deletes the last character (a comma in my case) from an input field.
How could I delete the last character from an input in JQuery? For example, onclick of something, it deletes the last character (a comma in my case) from an input field.
$(document).on('click', '.backspace', function(){
let value = $('#output').val();
console.log(value);
v = value.slice(0,-1);
let v = value.slice(0,-1);
console.log(v);
$('#output').value(value);
});
function back_space() {
var arrayexit = document.getElementById("tbtwo").value;
for (var i = 0; i < arrayexit.length; i++)
{
var output = arrayexit.slice(0, -1);
document.getElementById("tbtwo").value = output;
}
}
Html code
<input oninput="remove(this.value)" type="text" id="mytext" />
Js code
function remove(val) {
document.querySelector("#mytext").value = val.slice(0, -1);
}