Is there a way to catch all keyboard input in a browser? Im guessing it would have to be JavaScript.
My problem is that I have a USB Bar Code Scanner which the computer treats as a second keyboard. I dont want the user to have to click on the input box for bar codes to be entered in it. But I also want them to be able to hit key short cuts that perform an action that does not display that input in the text box. Also can the f1 - f12 keys be used in this manner or are they reserved for the browser itself?
keydown will fire for most keys (certainly more than keypress) in most browsers (some, such as Safari 3.0, won't fire any events for modifier keys such as Shift) and all keys in recent browsers. The behaviour of function keys is not a good thing to rely on though.
The following page is an excellent reference for key events in JavaScript: http://unixpapa.com/js/key.html
You can handle the keypress event for the document object, which will receive almost all keyboard input.
The exact behavior of function keys will depend on the browser.
I did this before. I used a timer. I give the input box focus and start the timer after the first keypress is detected, then if no other keys are pressed within 100 milliseconds I submit the form. The barcode scanner "types" pretty quickly.
You can also intercept the character codes to detect the F-keys.
Related
I'm trying to create an system that can calculate all input given for invoice related calculating.
What I'm trying to achieve is when I have multiple text fields (Yes I want to use text fields otherwise I would have used the build in validator for the number field)
So when I click out of a text box it needs to validate live if the input is numeric. and when its not it should show some message above it that it isn't and make the field red like an error. BEFORE submitting the form
And yes I know this is easily done with jQuery/ajax/php setups but I want to only use PHP. So IS there some kind of way to do this pure PHP or not because I can't seem to find some way or tutorial that does this.
Sorry if this question is shit but I'm at wits end now searched for 2 hours straight and cant even come close to finding some way that uses only PHP.
I'm using an hidden div and going to use style tags that only show when input is wrong so the errors/red colors are already done now I just need some kind of validator
Thanks in advance and again I'm sorry if this is a shitty question
If you want the validation on server-side in PHP you need to use either a ajax request on each click and send the data, or do the following before you echo or output anything, for example if your model or controller...Iterate on your data and run this regex rule on each of your values:
if( preg_match('/^[1-9]\d*(\,\d+)?$/', $inputValue ) ) {
// It is numeric
}
else{
// It is not numeric
}
I assume you use . as your decimal operator? If no, the rule should be:
preg_match(^[1-9]\d*(\,\d+)?$)
This will tell you if it's numeric.
Note that the $inputValue is the variable you are testing.
Because you want to validate a text box live on the browser (which is the client side), you cannot use PHP which is server side language to accomplish this. Sorry but you cannot.
I am developing a barcode reader application for personal use (inventory). The barcode reader I am using, acts like a keyboard, it inputs the barcode number and sends an "Enter". However, I always need to focus manually said text field.
I want to make the reader update the whole form of fields when it reads a barcode. Without having to place the focus manually on the field.
In order to do so, I was wondering if there's a way to determine if the keypress (or another event) came from the bar reader or from the keyboard?.
The development it's currently done under HTML/JS (jQuery) and PHP, but I'm not closed to other suggestions.
The barcode reader is plug and play, and didn't come with drivers. Is there a way to read the information on the device that is performing the input?
As far as I know there is no way of differentiating a (generic) barcode reader from a real keyboard. You may solve your problem by adding a keypress handler on a page with code that sets focus to the field you need to put the value into.
You can try adding the autofocus attribute in the html.
http://www.w3schools.com/tags/att_input_autofocus.asp
I have an about box on a profile page I'm working on (see below). Now that area shown by the textarea will have a PHP variable (about user column) produced in the space.
What I want to do is when a user clicks edit the paragraph content produced becomes an editable <textarea> which I can then save and it will write the new data to my PostGreSQL database and instantly show the new edit.
Basically I'm looking for a dynamically editable paragraph/textarea combo which will automatically update the database storing the original textual data in an about user column.
I have researched many JQuery examples like this on jsfiddle - http://jsfiddle.net/BenjaminRH/467S5/ but that doesn't have the database functionality I am looking for.
In essence, the HTML5 ContentEditable attribute could be perfect here.
This won't automatically update any databases, or anything for that matter, but nor will any other control that isn't some kind of composite made specifically for (and even genericised to handle) certain database types and scenarios and frameworks etc.
Therefore, in order to get this (a control that does it all) you're likely going to need to hunt down a third party product - there may be a free one (I've not seen one for the likes of PHP or ASP.NET or other major frameworks, and frankly I'm glad), or you may be stuck with having to buy one. As expected, I personally can't vouch for any, and wouldn't recommend such a plug n' play control anyway.
But, as per my first suggestion, there's half the task done - just write the code-behind in a reusable class and hook it up some how.
im writing a php pos system for my store, and im dealing with the barcode system now.
basically i want to be able to monitor the window, and when the barcode comes in put it in the input search box and submit it.
the 2nd part is the easy part, im having difficulty with the first part.
i made the scanner append te pipeline charecter (|) to the barcode, and i have jquery monitoring the window for any key presses that are pipeline, but how would i read the key presses after the pipeline once its triggered? maybe i have the wrong approach to this..?
Last time I built something like that, the page had a big fat <input> element, that was auto-focused. Your scanner acts as a keyboard, with the exception of pasting the string in one event, rather then emitting a key-events for each distinct character. (at least that was the case with our scanners).
add an <input> element, focus it. When your scanner sends a code, it will be written into the <input>. There you can react to keyup or change events to see if the code was written completely and then react accordingly. In our case, a newline (\n) was appended to the code to mark its end. But I guess a pipe (|) would be just fine as well.
I have a PHP form which lists all the people who will share the cost of an item. Next to each person, there is a blank field which you type the percentage of ownership. Currently, I have no mechanism to prevent you from allocating more than or less than 100%. For example:
Joe - 40%
Jill - 40%
Jane - 40%
The above scenario is currently possible and will break the math. Before submitting the form, I would like to verify that the entered percentages total 100. It would be nice if I could do this in real time (before submitting) but upon submit is okay too.
These values get entered into a MySQL DB.
Thank you!
Here is a javascript demo I made for you:
http://jonathancross.com/projects/form-validation.html
Code is not 100% complete, but should get you most of the way there. Would suggest adding support for up and down arrows on keyboard and of course a submit button :-)
Note about validation:
You will also need to validate the values on the server-side (php) to be sure they work before storing in the database. Javascript is great for immediate feedback, but is easy to circumvent (if someone wanted to break your app). It is also possible that users might disable javascript or use a browser which does not support it so beware and always validate on the server side.