View Full Version : Script: Form field Limiter (Error found)

11-19-2004, 01:25 PM
In general the scripts works very fine, but if you are using variable names for input or textarea like "var[]" to use a arrays for your form input then the script produces an error.

Because the use of arrays in form variables is a standard, the script should support this standard as well.

<input type="text" name="var" /> ...works fine with scipt
<input type="text" name="var[]" /> ...works not with script

Who can help, because my JavaScript Skill is not good ...?

with kind regards

11-21-2004, 07:42 AM
Is there nobody with a clue here ...?

11-21-2004, 10:19 AM
Well, it is the weekend. Also, please allow at least 2 to 3 days for a response, as I usually try and answer questions twice a week.

11-22-2004, 12:41 PM
Ok ... that sounds very good.
One completion: You can also use a full array name like "varname[value1]" for the imput's name and you will get the error as well.
And if someone is asking what the sense is for an array like this in forms ... then think about 100 inputfields and how you will use the posted data in a loop or push them to a function.
With arrays in a form you can save many code and accelerate your scripts.

11-22-2004, 10:00 PM

Ok, I see the problem. I'm still thinking about it, but this is a tricky problem, since by default JavaScript- and this script- requires that each form element have a unique name in order to work. The array syntax (ie: var[]) carters to server side languages like PHP and CGI, but never JavaScript.

I've made a note of the shortcoming of this script in this respect, though I can't say yet when to expect an update.

11-24-2004, 08:34 AM
Thank you for your investigations!
How unfortunate, because "varname[value1]" would be a unique name and Javascript support Arrays as well.

I'm not sure, but is it possible to use a unique ID instead the name of the element to proceed the functions ????
So I could write <input id="xyz" name="myFormArray[xyz]" type="text" ....

Best regards

11-24-2004, 08:46 AM
Yes, rewriting the script to use the ID attribute would be one option. It would be more of a hassle integration wise, as the webmaster would need to add the ID attribute to the form elements in question while with the name attribute, it's normally already present.

I'll give this some thought.

11-24-2004, 07:04 PM
Ok, then I'll still waiting for your grandiosely solution :-)
.. but the "ID Solution" would be really good enough for me.

Best regards

12-04-2004, 07:29 PM
Could someone give me a hint how the change the script to use IDs ??

12-07-2004, 07:06 AM
Good news. The script has just been updated for this, so it now supports both input by name or ID. :) Here it is: http://www.dynamicdrive.com/dynamicindex16/limitinput.htm

12-10-2004, 03:18 PM
GREAT ! I'll test it on the weekend. Thank you!!!