I'm wanting to take whatever is entered into input and when the button is clicked, it removes everything after the first two characters that were entered.
For example if I entered in "BT2J43" I would like it to cut it down to "BT" in the input field is the possible?
Here's my fiddle below, I'm just learn jquery, go easy on me!
https://jsfiddle.net/ktd9gbu9/1/
$("#submit123").click(function() {
$("#text123").text($("#text123")[0].innerText.substr(2));
});
<input type="search" name="table_filter" id="text123" required>
<input name="submit" type="Submit" id="submit123" value="Search">
You want to use .val()
instead of .text()
:
$("#submit123").click(function () {
$("#text123").val($("#text123").val().substr(0, 2));
});
jsFiddle example
Also with substr() you forgot the starting index.
You can do that easily but you need to target .val()
Here is a clean code that may help you! :)
$("#button").click(function () {
var search = $("#search");
search.val(search.val().substr(0, 2));
});
There you go with JSfiddle Example
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I have a directive where I am including some jQuery like this:
I am getting a very generic error message from an Ajax calls xhr parameter
The following code was working fine in previous jquery mobile versionsAfter update the panel does not open after switching pages more than twice