Will Oller .com

Avatar

Learning to match the beat of the Old World man.

Use Firebug to Update A Huge Form

Had a problem recently where I had to update hundreds of input fields within a shopping cart, setting prices of product variants from $200 to $49.

They were named in sequence:

JAVASCRIPT:
  1. ...
  2. <input name="vs[1667][price]" value="200" />
  3. <input name="vs[1668][price]" value="200" />
  4. <input name="vs[1669][price]" value="200" />
  5. ...

So I busted out the command line in Firebug.

JAVASCRIPT:
  1. for (var i=0; i<10000; i++) {
  2.    if(document.productvariantsform.elements["vs[" + i + "][price]"].value) {
  3.       document.productvariantsform.elements["vs[" + i + "][price]"].value = "49.00";
  4.    }
  5. }

but all I got were "has no properties" errors.

I got in touch with my local Javascript guru who helped me come up with some code that did work:

JAVASCRIPT:
  1. var frm = document.productvariantsform;
  2. for (var i=0; i <frm.elements.length; i++) {
  3.    if ((frm.elements[i].name.match(/\[price\]$/)) && (frm.elements[i].value)) {
  4.       frm.elements[i].value = "49.00";
  5.    }
  6. }

This saved literally hours of [TAB][TAB][TAB][TAB][Ctrl+V].
Thank you Firebug!

del.icio.us:Use Firebug to Update A Huge Form digg:Use Firebug to Update A Huge Form reddit:Use Firebug to Update A Huge Form

No Comments, Comment or Ping

Reply to “Use Firebug to Update A Huge Form”