Need Help with some javascript validation.

Syran

Gawd
Joined
Apr 26, 2007
Messages
683
I'm working on a form that uses javascript-coder's gen_validatorv4 script. (Have used it in the past to great success). This form is so that tellers at the bank I work at can put information in on voided checks, to send back to our accounting department and get kicked out as a csv for Foxtrot.

I have tested the script in Firefox and Chrome, with no problems. However, in IE 8 and 9, I get the message "Line #1: Your account Number must be a number!", which is a validation error for not putting a number in that line, and as far as I can figure, it's because I'm using a 1D array. It will repeat again with an error when attempting to do it under maxlen as well. I'm using the array (which is created by the previous form) as there is a variable set of number of checks which may be submitted at any given time.

I added the array-0.9.js file from js-methods, and that has slightly fixed the issue by adding an ability to handle indexes in Internet Explorer. It now properly validates the first line of items up to the radio button, but fails at that point. If I remove the radio button check, it will then fail on the 2nd row on num and maxlen verification. Please check this fiddle for the code. I've intentionally not included it in this part of the thread, as it gets kinda long.

Anyone have any ideas how to make it work in Internet Explorer properly?

Thanks!
 
Remove the square brakets in your name tags. I have never seen anyone do that. I would recommend using a hypen if you want to break it up. EG 1-acctnum
 
Remove the square brakets in your name tags. I have never seen anyone do that. I would recommend using a hypen if you want to break it up. EG 1-acctnum

If the backend is PHP, they will be interpreted as arrays, but I'm unsure how the numeric indexes will turn out.
 
Remove the square brakets in your name tags. I have never seen anyone do that. I would recommend using a hypen if you want to break it up. EG 1-acctnum

That's setting up the array in the form. Makes it much easier to traverse the data on the back end, the problem is that it could have 1 set of fields, or 20. I used numbers for ease to ID items.

If the backend is PHP, they will be interpreted as arrays, but I'm unsure how the numeric indexes will turn out.
I am using PHP/Mysql for the backend.

The form, when submitted, looks something like this:
Code:
Array ( [bid] => 1 [tid] => 1 [1] => Array ( [date] => Array ( [month] => 5 [day] => 7 [year] => 2013 ) [actnum] => 12345 [serial] => 12345 [amount] => 12345 [type] => 1 ) [2] => Array ( [date] => Array ( [month] => 5 [day] => 7 [year] => 2013 ) [actnum] => 12346 [serial] => 12346 [amount] => 13246 [type] => 2 ) [action] => check )
I can then traverse it much cleaner then if I had it split out written, especially when I get to the 2D arrays (the dates).

Unfortunately, the problem seems to be that IE's version of Javascript does not properly transverse the array like it can with Chrome or Firefox (haven't tried Opera or Safari, but those browsers aren't in use here.)
 
Last edited:
The main issue seems to be that on line 199 of gen_validatorv4.js
Code:
var itemobj = this.formobj[itemname];
returns the element 'tid' when itemname="1[type]" in IE, instead of a NodeList containing the two radio elements.

Edit:

Found the issue. NAME tokens must begin with a letter. Simply change name attribute to begin with a letter instead of a number and it'll work.

I'll submit this issue to Microsoft just for kicks, just to see what they have to say.
 
Last edited:
The main issue seems to be that on line 199 of gen_validatorv4.js
Code:
var itemobj = this.formobj[itemname];
returns the element 'tid' when itemname="1[type]" in IE, instead of a NodeList containing the two radio elements.

Edit:

Found the issue. NAME tokens must begin with a letter. Simply change name attribute to begin with a letter instead of a number and it'll work.

I'll submit this issue to Microsoft just for kicks, just to see what they have to say.

Thanks! I'll take a look at trying that out at work tomorrow.
 
Thanks! I'll take a look at trying that out at work tomorrow.

Woot! Thank you Snowknight26!!!

Got it working here by changing it to a1[field] vs 1[field]. But that really didn't sit right, it makes it (imho) harder to traverse an array with that kind of name, so I ended up going with a 2D array here using stuff[1][field]. It tested and worked. I'll probably tweak it a little for naming to make sense; but it's all good!
 
Back
Top