Faking out a field exit (redux)

Strongback Consulting

This is a post I had made on the HATS newsgroups a couple of years ago. I’ve had to go back and search for it a couple of time recently, so I though I’d put it where I can most easily find it… on my own blog. HATS 7 does the field exit for you (99% of the time), so you should not have to add this. However this trick is handy if you need to add some validation that the green screen does not already provide.

For those of you struggling with field exit, here is a way to implement
it with JavaScript. On your widget for the input field, click the
properties. For the ‘Style’ option, enter the following:

” onblur=”fieldExit(this,4)”

The first quotation mark terminates the style element while creating the
onblur attribute for the HTML element. Next, add the javascript
function. I always recommend putting your JavaScript in js library. Here
is the function:

function fieldExit(field, fullLength){
var val = trim(field.value);
var missing = fullLength-val.length;
for(x=0;x
val=’0’+val;
}
field.value=val;
}

The fullLength variable is the maximum length of the field that you are
trying to field exit. Finally, if you have created a submit button (for
the [enter] event), add javascript for an onclick event to move the
cursor position out of the last field, to ensure the field exit function
fires.

Here is an example. The first argument of setCursorPosition is the
absolute cursor position. This position is a calculated number and is made up of the following formula: (# rows-1) x 80 + (# columns). In other words, a field at row 5, column 30 would have an absolute position of 350 (80(5-1) + 30).


href=”java script:ms(‘[enter]’,’hatsportletid’)”
onclick=”setCursorPosition(596, ‘HATSForm’);”>Search

One Response to “Faking out a field exit (redux)

  • I’ve been searching all over the place for a way to make javascript emulate the field exit command. In trying to migrate some green screen apps into web apps it has come up as a request from customers to retain that functionality. Can you clarify the field exit function code? The for loop looks incomplete, or am I just looking at it cross eyed?

    Thanks a ton. You can email me at brycekmartin@gmail.com if you would like.

Strongback Consulting