Reputation: 99
So i have Two textboxes, both being used by Barcode scanner. Textbox1 is material and Textbox2 is progress. I would like to clear TB1 and TB2 when TB2 scans "F4" and focus Textbox1.
I couldn't figure it out so i came to you stack.
Thanks for any help.
Upvotes: 1
Views: 1324
Reputation: 67898
So capturing bar code scans is tricky. The event model is the problem. To make matters worse, you're using ASP.NET so it's going to be even harder. But, it's possible with JavaScript. Consider the following jQuery:
$("#textBox2").on('keyup', function(event) {
o = $(this);
if (o.val() === 'F4') {
// post the values back to the server via AJAX
// clear the text boxes
$("#textBox1").val('');
o.val('');
// focus the first text box
$('#textBox1").focus();
}
});
where #textBox2
is the id
attribute of the input
element you want to interrogate and #textBox1
is the id
attribute of the input
element that houses material value.
This could technically be hacked with the ASP.NET post back model, but it wouldn't be pretty. You'd have to use the same JavaScript event to actually force a post back:
$("#textBox2").on('keyup', function(event) {
o = $(this);
if (o.val() === 'F4') {
$('#formName').submit();
}
});
where #formName
is the id
attribute of the form
element you're inside of.
And then server-side you'd have to consume the TextChanged
event of the second text box and check its value to know you ought to clear the values of both. It's just a little fickle.
Finally, using this post back model, you'd have to register some client startup script to set the focus to the first text box because you'll need some JavaScript to do that. As you can see, it just gets uglier.
Upvotes: 1