21 Feb 2006
Today I had to cook up a simple form with two input fields, so that two barcodes could be scanned into their respective fields and then submitted (the point being to link two IDs in a database that have been encoded in separate barcodes). There was one twist.
The barcode reader automatically appends a return character to the end of the string it’s read… which would, in any normal circumstance, submit the form. Obviously problematic unless we split the form over several pages, which is just yuck.
If the barcode reader hadn’t returned character 13 (return/enter/whatever you’ll call it) at the end of the string, it’d be trivial to pick up a “maxlength=x then go to next field” script off the side of the road… they’re everywhere. Not so much the case with this exact problem, though, so I thought I’d share…
[source:str javascript]function catchEnter(e){
var characterCode
if(e && e.which){
e = e
characterCode = e.which
} else {
e = event
characterCode = e.keyCode
}
if(characterCode == 13){
document.getElementById(‘cardid’).focus();
return false
} else{
return true
}
}[/script]
Note we’re not using DOM methods here… there isn’t any equivalent to which
or keyCode
that I’m aware of (I looked enough). keycode
is the important one… which
is used by the likes of Netscape 4.x and other nasties… I don’t really want to know about it, but I stole the key trap code from somewhere (lost the site) and didn’t really have a reason to intentionally break the behaviour for those browsers!
So we use one of those (probably keycode) to set characterCode, which is a numeric value that corresponds to Unicode decimal values. 13 is carriage return. Then it needs to be compared to event
(the character that triggered the onkeypress event), here used as e
for convenience… and if this is true, then focus will go to the next field (in this case cardid
) and the character will return false
to prevent the form from submitting.

I’ve got a static demo here (don’t mind the message at the top, it was an HTML mockup)… try entering something into the first field and pressing return. Then press return again, and the form will submit.
Obviously this Javascript only works for a two-field case… but you could dynamically set the element for focus to follow to by parsing that through to the function onkeypress
event. The only other thing I can think of is to getElementsByTagName every input field in the form and use the array to dynamically set the “next” field… but that would have been waaaay overkill for what I had to do.
This behaviour isn’t just useful for barcode scanners, by the way. Desktop applications often exhibit this kind of behaviour, and it also goes some way to ensuring all fields are filled without doing formal validation (either JavaScript on submit
, or server-side).
18 Feb 2006

Tori turned 18 yesterday and had an awesome party (even though she caught a cold the day before… apparently my fault, even though she hadn’t seen me when I was sick!). I’d post photos, but most of the half-decent ones I took are on her camera (half-decent because I can’t really ever take “party photos” with any finesse).

There was ice-cream cake. Oh was there ice-cream cake. Yum.
*ahem*
Anyway, happy birthday Tori… and get un-sick soon!
15 Feb 2006
It requires Java. I can live with that, it’s a web application.
I had to call up to find out what browsers they officially supported, only to be told that support was limited to Internet Explorer on Windows, Mac (!!) and Netscape 7+ on both platforms. Firefox “hasn’t been tested”, Safari hasn’t been looked at. I’m not particularly keen on this, but hey, they’re a bank… we all expect them to be a bit backwards.
The application sniffs for a Java Virtual Machine and refuses to load without even providing an error message if one isn’t detected. This wouldn’t be so bad but for the fact that it checks explicitly and exclusively for the Sun virtual machine… so anyone who doesn’t use that platform for whatever reason (licensing, ethical, platform) — even if they have another fully compatible virtual machine — can’t get access.
My solution? Disable Java (not JavaScript) altogether using the Web Developer’s toolbar, then sign in (it doesn’t choke!), wait til you get to the main applet pane, re-enable Java, and press F5. Magic, it works.
There is absolutely no reason or excuse for this behaviour. If this fits into some perverted notion of security, I’m not comfortable having my money there. If it’s the product of an incompetent web team… well… they’re an incompetent web team. Grr.
I called up and asked why it wasn’t working, then explicitly asked for a report to be forwarded to the web team. Please lots of people do this (heh, you don’t even need to be with St George… they didn’t ask me for a name or account number during the phone call!)… this service is unneccessarily stupid at present!
On a plus side, their phone service is good fun. I couldn’t find a support number quickly, so I called the dragondirect number provided on a letter (1300 30 10 20) and when none of the options matched “support”, I just hammered “9″ repeatedly. Works on a lot of PBX systems, and it worked there… I got through to a human within 30 seconds, who then put me straight into the queue for web support. Good stuff.
15 Feb 2006
I discovered an article on setting focus on the next field after a selection is made in a select
option menu thingo, which looks pretty handy to have around. It could potentially be a bad thing, too, (if the user selected the wrong option + does repeatedly), but generally speaking this looks like a handy piece of code to have around.
14 Feb 2006
This is one of those “blanket” posts that attempts to cover everything that happened (or didn’t) over the last few days. As you may have picked from the thoroughly disconnected title.

Sunday saw a trip to the day/night cricket semi-final between Australia and Sri Lanka (I say that like I know what’s going on, but I had to ask Dad who was playing that morning. ’twas purely a social thing for me!) with various friends from church.

It was pretty good times, but I managed to get burnt despite putting sunscreen on every hour (it was 4hr SPF30+ cream!). I think I missed part of my arms (the underside!) in the first hour, and by the second hour they’d already been sufficiently damaged to start turning bright red (it was about 2pm… yeah, easy to burn here in Oz). The Sri Lankans (spelling?) lost, but looked like they were having the most fun of anyone in the ground regardless!

So yeah, it’d rock to be Sri Lankan!
Anyway, I ate some horrendously-overpriced-sport-venue food, probably didn’t QUITE drink enough water (probably drank about 3L at the cricket alone, but was sitting in full sun, so…), and hadn’t been sleeping terribly well for the past week (or two). I’d been sticking my hand up for a few too many things some weeks back and it all finally started to come unravelled last week, I guess. Hopefully things will get better from here, we’ll see. So yeah, various factors… I got home and inside okay (albeit with a massive massive headache), went upstairs, and lost nearly everything I’d eaten that day. I got to bed but only for fourty minutes or so before I woke up again… found I apparently had more food left in my stomach! Doh.
I didn’t go to work yesterday, and spent most of the day in bed… reading Harry Potter (because I still hadn’t read book 5 and a whole day is time enough to finish pretty much any book). The headache had mostly subsided and stomach was fine by the end of the day, but I’ve got a cold now… shrug. Tis very odd. I was at work today but felt kind of lethargic + not that productive… but it was better getting some stuff done than spending another day in bed doing nothing (mind you, it would have been back to Great Expectations followed by North and South if I’d stayed home… hmm…). We’ve got a whole bunch of exciting stuff lined up for the Sunrise Family website which is getting rolled out soon, but obviously don’t waste your time looking if you don’t watch the show (I know I wouldn’t! Once various features launch I’ll probably post geeky details here… we’re looking at social media stuff especially (which shouldn’t come as a surprise to those who know Yahoo!’s acquisition patterns, but seeing as 7 is very much MSM it’s pretty exciting), integration with products from Yahoo!’s stable, etc.
So yeah, that’s what’s been happening. Consider blogging un-slipped.