0

I have a Javascript problem that I cannot find the answer to. Hope you can help me.

I have this element called 'scanValue', that has an onFocus and an onBlur trigger:

<input name="scanValue" class="searchFormText" style="width: 220px; font-size: 22px;" onfocus="onFocusElement(this)" onblur="onBlurElement(this)" type="text" maxLength="20" value="510210006823414"/>

If I tab out of the field the onBlurElement() function is called as expected:

function onBlurElement(object) {
        alert('onBlurElement: Start blur on ' + object.name + ' (old val = ' + prevObjectVal + ', new val = ' + object.value + ')');

        if (object.value !== prevObjectVal) {
            check(object);

            var checkFcn = 'check' + object.name;
            var fcnParms = [object.value];
            var fcn = window[checkFcn];

            alert('onBlurElement: check if ' + checkFcn + ' is a function: ' + (typeof fcn));
            if (typeof fcn == 'function') {
                alert('fcnParms length = ' + fcnParms.length + '. ToString= ' + fcnParms.toString());
                alert('fcnParms[0] length = ' + fcnParms[0].length + '. ToString= ' + fcnParms.toString());
                fcn.apply(fcn, fcnParms);
            }
        }
    }

Now this dynamic function call (fcn.apply()) should call the function 'checkscanValue(val)', but nothing happens. EXCEPT when I add an alert() to this function OR if I fire up the IE standard developer tools. In other words, if I track or debug the checkscanValue() function everything works, otherwise is does nothing. I've tried several different things, but nothing seems to work. I doubt this could have anything to do with the form being submitted with method post, but maybe someone could help me on that.

Code for the checkscanValue() function:

 function checkscanValue(val) {
        console.info('checkscanValue: start function');
        document.forms[0].airNumber.value = 'test';

        // Check if the scanned value is valid for submitting the form
        if (val[0].length === 15) {
            document.forms[0].submit();
        }
    }
  • The airNumber field is also on the form, and the value is not changing. –  Sep 04 '14 at 08:02

2 Answers2

0

Everything is working fine except that the "val" parameter that you are passing to the checkscanvalue function is the string that the user entered or is there by default.

So val[0] returns the first character of the string whose length can't be 15 and hence the check fails and nothing happens.

hope it helps!

daksh_019
  • 802
  • 7
  • 16
  • Thanks, what you are saying is correct. Problem is that my code was changed after attempting almost everything I could think of. The original code was without the array index, and that didn't work. Besides, the update of the form field airNumber is also not working. –  Sep 04 '14 at 08:45
  • I used a text type input and the value updates fine. let me know the input field that you are using in the form. – daksh_019 Sep 04 '14 at 08:50
  • I looked up some info on the console.info() function, this is not standard, could this be the problem? It works if I change it to an alert() or if I fire up the console. –  Sep 04 '14 at 09:09
  • I tested it with the input element you mentioned and i get the output as expected without any alert, console or debugging. Provide the onfocuselement function if you can. PS :make sure that the values in class, name etc are in quotes. – daksh_019 Sep 04 '14 at 09:20
  • I have removed the console functions and now it works! Not sure why? –  Sep 04 '14 at 09:28
0

This seems to answer my question: 'console' is undefined error for Internet Explorer

I've been using the function console.info() which is undefined if the console window of IE was never opened. This caused the function to stop. If I replaced it with an alert() it obviously worked and if I opened the console of IE, the console.info function was defined.

Community
  • 1
  • 1