javascript - For loop issue in FireFox -


I am working on a script that removes the default value in form elements using prototype and lightview. The script works fine in Safari, but not at all in Firefox (3.5.5).

A fire starts when the light begins.

document.observe ('lightview: opened', function () (if ($ ('contact_form')) {var defaults = new Array (); var ins = $ ('contact_form' ). GetElements (); var inlen = ins.length; for (i = 0; i & lt; inlen; i ++) {Warning (i) if ($ (INS [i]) readAttribute ('type') ! = 'Image') {Default [INS [i] .name] = $ (INS [i]) Value; $ (INS [i]). ('Focus', check default.top (event, ins [i] ]);}} Function check default (name, event) {alert (name.name)} ($ (name) .value == defaults [name.name]) {warning (default [name.name]) $ (Name) .value = '';}}}});

It's weird, when I check the inline length, the appropriate number is alerted, but when I give 'I' warning, only the first number is alert She goes.

Any idea which is wrong here

The address of this problem:

Thanks Rich

I'm not sure that this would be the cause of that problem, but you can not use it for var :

  (var i = 0; i & Lt; inlen; i ++) {<>  

Besides, there is no semi-colon after any of you alert () s.

Try to improve them, and see if it makes any difference.

Edit:

As stated by Matt, in the comments: ignoring the var variable in the global scope makes. Prototype uses a global variable i , but this makes me suspect that it can cause a problem.

Edit 2:

Another possibility is an array accessing by input name:

  defaults [ins [I] .name] = $ (ins [i]). Value;  

Try declaring default as an object:

  var defaults = {};  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -