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!

Turns out if I’m drunk and you…

Turns out if I'm drunk and you ask me an economics question, I can't play guitar hero until I explain supply-side economics to you.

Oh yeah. Goin’ to AEA SF08. Th…

Oh yeah. Goin' to AEA SF08. Thanks, Mike!

There is a tide in the affairs…

There is a tide in the affairs of men
Which, taken at the flood, leads on to fortune;
Omitted, all the voyage of their life
Is bound in shallows and in miseries.
On such a full sea are we now afloat;
And we must take the current when it serves,
Or lose the ventures before us.

- William Shakespeare, Julias Ceasar

A lesson in procrastination: I…

A lesson in procrastination: If you wonder to yourself "should I get my bag out of the car now or wait until tomorrow morning?" - you should go get it now, because in the morning your wife is going to leave for work and take the car, and your bag.

Continue Previous page Next page