Forum Moderators: open

Message Too Old, No Replies

Possible to strip ENTER key from forms?

Barcode scanner adding ENTER after scanning

         

salewit

8:44 pm on Mar 6, 2008 (gmt 0)

10+ Year Member



I've got an old barcode scanner that injects an ENTER key after filling out the barcode value. For those not familiar with barcode scanners, they perform EXACTLY as if someone is typing on the keyboard. So if a barcode is 123-456, the scanner would "type" 123-456<ENTER>

The problem is that this ENTER is causing the "SUBMIT" button to be pressed. I want to somehow strip the ENTER key from each scan and fill a form, and then have the user click on the SUBMIT form. I know very little Javascript. Is this possible?

MarkFilipak

8:59 pm on Mar 6, 2008 (gmt 0)

10+ Year Member



Javascript runs only inside a web browser (exception: Internet Explorer can access some Windows API via active-X). How is the output of the scanner getting into the browser?

In javascript, your string would be represented by "123-456\n". "\n" is known as the end-of-line which will generally work for carriage-return+line-feed also.
If you search for that string, you need to add an extra backslash, for example:

myText.replace(/\\n/g, '')

would strip the end-of-line.

[edited by: MarkFilipak at 8:59 pm (utc) on Mar. 6, 2008]

salewit

9:14 pm on Mar 6, 2008 (gmt 0)

10+ Year Member



It's a simple HTML form. I guess the easiest way to think about it would be to think of it as a person entering the text and the ENTER key in a form. So a form might have:

Name:
Address:
City:

But the user enters "John Wayne<ENTER>" and the form is submitted prematurely. I need to somehow capture that ENTER key "on the fly". Either that or disable the SUBMIT button from being "pressed" with the enter key.

gergoe

9:28 pm on Mar 6, 2008 (gmt 0)

10+ Year Member



You would simply need to remove the
<input type="submit" ...>

element from your form, and replace it with an element like this one:
<input type="button" onclick="document.yourFormsName.submit();" ...>

If you are using form validation, then preferably call that first, and then submit the form, but that's just a minor inconvenience.

This will make the Enter/Return key do nothing, because the browser will not know what is the "default" action to do, so it discards that. You can achieve the same (although not that reliable) effect by adding more the one submit buttons to your form (to confuse the browser; but I'd not count on that).

plumsauce

10:07 pm on Mar 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




You might be able to configure the barcode scanner to not emit the return key, or translate it to a tab.

You can also try the onkeypress event.

salewit

2:16 am on Mar 7, 2008 (gmt 0)

10+ Year Member



Hey that was pretty easy and it worked great. Thanks so much!

Plumsauce: It's an old scanner, and it isn't configurable. You're right, the newer ones allow you to set it up as ENTER or TAB.

vol7ron

10:30 pm on Mar 7, 2008 (gmt 0)

10+ Year Member



Instead of bypassing the enter key, could you just validate your form before submit?

onsubmit="return validateForm();"

function validateForm(){
...are all fields filled out?...
yes ? return true : return false;
}

If it's a set # of fields and you know a certain # of <ENTER>s are going to be sent, then you could also just use a global count. Or, instead of validating all of the boxes, maybe you could just validate the last one?


vol7ron




[edited by: vol7ron at 10:37 pm (utc) on Mar. 7, 2008]

vol7ron

10:36 pm on Mar 7, 2008 (gmt 0)

10+ Year Member



Also, check out this bit of code from W3C


<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}

keychar = String.fromCharCode(keynum);
numcheck = /\d/;
return !numcheck.test(keychar);
}
</script>

<form>
<input type="text" onkeypress="return noNumbers(event)" />
</form>

</html>

You might be able to modify it so that in place of numcheck = /\d/ you can try the /\n/ as Mark suggested. Notice how this is using a window event.


vol7ron




turbosaab

1:09 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Another handy snippet for disabling the enter key:



function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}

document.onkeypress = stopRKey;


vol7ron

3:23 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Nice turbo, but does the node.type have to equal text? It's form submission rather than text-box.

Just curious,
vol7ron




penders

4:08 pm on Mar 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...does the node.type have to equal text? It's form submission rather than text-box.

By the look turbosaab's method could also be used to solve the OP's problem of form submission (without modification) if barcode scanners "perform EXACTLY as if someone is typing on the keyboard" - I assume using a text box?

But in general terms I don't think the node.type needs to be limited to "text". "radio" and "checkbox" could also be useful. However, it would be wrong to surpress the enter key on some elements. <textarea> for instance does not cause a submit if the enter key is pressed and indeed it is useful here. Also if the user was able to TAB to the submit button, then hitting enter would naturally action it.

salewit

4:34 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Thanks for all the input here (no pun intended). It turns out that for my particular application, I actually needed more than I thought. What I'm trying to do, and I've all but given up, is to create a simple POS system for when I go to trade shows to sell my product. I've got a regular online site, but when I lug 400 items to a trade show to sell, I have to meticulously write down every item I sell, so that when I get home, I can quickly update the online inventory. So I bought a cheap barcode scanner and thought I could just plug it into my laptop and I can create a simple form to do that, but it hasn't been the case. Ideally what I'd like to do is simply have it like a checkout at the grocery. If someone buys 4 different items, I just scan them in. So I guess maybe what I'm looking for is to CONVERT the enter key to a TAB key so just the act of scanning would cause the form entry to go to the next field.

MarkFilipak

7:28 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



> needed more than I thought ... I've all but given up

Why? You don't really say. This is an interesting problem to me and worth exploring.

vol7ron

8:16 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



Bar Code Scanner - to - Microsoft Access

When you get home upload Microsoft Access to your mySQL or Access Db you have online. Use the database form as your driver for this, not your html form. (My personal opinion)

salewit

9:23 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



vol7ron: We're using MySQL on a shared Linux server. Anyway, we're out trade shows WITHOUT Internet access.

Mark: I've kind of given up because it's a little over my head. I've already installed Xampp on my Laptop, so I have access to my website and database "offline". Maybe I don't want to use a web form at all for this. I basically would like it to work like a cash register... I scan an item, and it pulls up the price (which I can edit if someone wants to bargain with me as they do), then I can scan the next item and however many items there are, and only then click the TOTAL key or whatever. So I'm looking to record the items sold at the show, preferably record the price paid next to each item, and the final wishlist would be to total the transaction for that sale, so I don't ALSO have to fidgit with a calculator to get the total. It can be a fast moving environment at times. Oh yeah... I also need to make it fairly simple for my wife... no having to manually "focus" on the current form field.

MarkFilipak

11:20 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



There are basic cash register applications out there. I think that some are even open software (free or nearly free) applications. Give it a Google.

salewit

1:11 am on Mar 11, 2008 (gmt 0)

10+ Year Member



Yeah maybe I'm trying to reinvent the wheel here. Great idea!

vol7ron

5:05 am on Mar 11, 2008 (gmt 0)

10+ Year Member





salewit wrote:
vol7ron: We're using MySQL on a shared Linux server. Anyway, we're out trade shows WITHOUT Internet access.


I do not understand what you're saying here. Access is an application that can be used w/o the internet. It is a standalone app. I'm not as familiar with using Access on Linux, but Open Office should have a comparable product. If not, there should be some sort of form submission with a background scripting language that can handle this request on the road.

In any case, if you are not using the internet to perform this task, you should look at using HTAs (HTML Applications) to perform your task. Though, I think the biggest problem is with the interface.

salewit

4:21 pm on Mar 11, 2008 (gmt 0)

10+ Year Member



I guess I'm confused too. I got thrown off when you said to "upload Access to your MySQL online". Maybe what you mean is to simply create a database in Access and sync it somehow with the online MySQL?

When you get home upload Microsoft Access to your mySQL or Access Db you have online. Use the database form as your driver for this, not your html form. (My personal opinion)

vol7ron

5:12 am on Mar 12, 2008 (gmt 0)

10+ Year Member



There were two separate thoughts there, but I'll explain. If you have Access, it's much easier to use its forms with older scanners, to handle problems like these. Because you're on the road, I figured you wouldn't be constantly connected to the internet, so I was saying when you get home upload it to your online database, whether that is mySQL or Access.

The real question is, since you're on the road, why can't you just scan to a CSV or txt file and import the data later?

MarkFilipak

9:19 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



> why can't you just scan to a CSV or txt file and import the data later?

salewit is trying to process the sale at the point-of-sale (a show). The db stuff is peripheral to the problem.

I agree with vol7ron. You should be able to do this with Access (or Excel) plus a WSH script.

vol7ron

9:46 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



Even still, store in a temp txt/csv file and filter the file with some sort of scripting language, or even a program, and insert to the database from there.

salewit

9:57 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



Yeah this is what I originally intended to do, but my only reservation is this... If I just have like Wordpad or Excel open, and scan titles into it, that's fine, but I'm worried that because I'll also be looking up items for customers using my offline database, I'll lose "focus" on the program and not notice while happily scanning away into nothing. I'll have someone helping me, and they too will access the database as well. It will work, and it's probably what I'll do, but I was really hoping for something I can scan a few items in without touching anything but the scanner and have it give me a total for the current sale (so I don't have to use my calculator ALSO).

I looked at and tried a few POS open source programs, and they either use their own proprietary database system with no import function (we have 800 different items), or they require scanning, then tabbing over a bunch of fields to get to the next line for each item. It's going to be too much in a busy environment.

I will also explore the Access method.

MarkFilipak

10:38 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



> tabbing over a bunch of fields to get to the next line...

The POS input form should be configurable. Maybe you didn't look hard enough.

> they too will access the database...

Uh-oh! Record locking time! Forget Excel. Maybe even forget Access.

[edited by: MarkFilipak at 10:41 pm (utc) on Mar. 12, 2008]

salewit

11:13 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



haha No I meant accessing that same laptop. Not database sharing on different machines.

But you see my problem right? Lets say I've got Excel on the screen, and the next open cell is ready to go. My helper clicks on our database to check something for a customer. The place is busy and frantic. He forgets to click back to Excel and make sure the cursor is at the next empty cell. It seems like a recipe for disaster.

The POS software I looked at was horrible. Most I found in my search were Linux based.

vol7ron

2:37 am on Mar 13, 2008 (gmt 0)

10+ Year Member



It's been a while since I've dealt with an issue similar to this, but I believe once you have a output stream open to a file, the operating system places the file in a write-locked state, but to everyone else the file should be read-only.

1) Why does the text file have to be constantly open? Can't you just configure it to write to the file without it another application having it open.

2) Did the scanner come with any software? I would assume there would be a way to change the focus if a scan has been performed, or even the fact that you can input directly to a file, without any application at all.

As for record-locking, this would only be a problem if two people were updating a record at the same time. More-than-likely a table level lock would not be needed, a dbms such as Access should be able to input from multiple sources at the same time.

PostgreSQL is a strong free database available on Linux, there is an open-source project dealing with forms, which I haven't used yet, but might be worth taking a look at. The good thing about PostgreSQL is the ability to work with whatever language you're comfortable with (C,Java,Perl). I think Perl would be the most robust.