May 13, 2008
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:
...
<input name="vs[1667][price]" value="200" />
<input name="vs[1668][price]" value="200" />
<input name="vs[1669][price]" value="200" />
...
So I busted out the command line in Firebug.
for (var i=0; i<10000; i++) {
if(document.productvariantsform.elements["vs[" + i + "][price]"].value) {
document.productvariantsform.elements["vs[" + i + "][price]"].value = "49.00";
}
}
I got in touch with my local Javascript guru who helped me come up with some code that did work:
var frm = document.productvariantsform;
for (var i=0; i < frm.elements.length; i++) {
if ((frm.elements[i].name.match(/\[price\]$/)) && (frm.elements[i].value)) {
frm.elements[i].value = "49.00";
}
}
This saved literally hours of [TAB][TAB][TAB][TAB][Ctrl+V].
Thank you Firebug!



No Comments, Comment or Ping
Reply to “Use Firebug to Update A Huge Form”