Jump to content

How To Shorten This Js Code


needs_upgrade

Recommended Posts

How can i shorten this code?

 

var quantity1 = +document.AddPO.quantity1.value;
var quantity2 = +document.AddPO.quantity2.value;
var quantity3 = +document.AddPO.quantity3.value;
var quantity4 = +document.AddPO.quantity4.value;
var quantity5 = +document.AddPO.quantity5.value;
var quantity6 = +document.AddPO.quantity6.value;
var quantity7 = +document.AddPO.quantity7.value;
var quantity8 = +document.AddPO.quantity8.value;
var quantity9 = +document.AddPO.quantity9.value;
var quantity10 = +document.AddPO.quantity10.value;
var quantity11 = +document.AddPO.quantity11.value;
var quantity12 = +document.AddPO.quantity12.value;
var quantity13 = +document.AddPO.quantity13.value;
var quantity14 = +document.AddPO.quantity14.value;
var quantity15 = +document.AddPO.quantity15.value;
var quantity16 = +document.AddPO.quantity16.value;
var quantity17 = +document.AddPO.quantity17.value;
var quantity18 = +document.AddPO.quantity18.value;
var quantity19 = +document.AddPO.quantity19.value;
var quantity20 = +document.AddPO.quantity20.value;

 

will this work?

for (var i=1; i<21; i++) {
var quantity[i] = +document.AddPO.quantity[i].value;
}

 

thanks a lot.

Link to comment
https://forums.phpfreaks.com/topic/270775-how-to-shorten-this-js-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.