Forums
This topic is locked
Can someone Simplify / Improve this JavaScript code?
13 Feb 2009 14:06:19 Frank D. posted:
Hi all,I'm not a JavaScript expert and I hope someone can help me out with this. The code below is working properly (as long as i2 is no more than 5). Is there a way to simplify/improve the code? It would really help me out!
Many thanks in advance!
function setAccParam() { var paramString = ""; var i2 = document.form1.AantalAcc.value; // total records of the recordset if(i2 == 1) { var param1 = document.form1.acc1.value; var param2 = "0"; var param3 = "0"; var param4 = "0"; var param5 = "0"; } else if(i2 == 2) { var param1 = document.form1.acc1.value; var param2 = document.form1.acc2.value; var param3 = "0"; var param4 = "0"; var param5 = "0"; } else if(i2 == 3) { var param1 = document.form1.acc1.value; var param2 = document.form1.acc2.value; var param3 = document.form1.acc3.value; var param4 = "0"; var param5 = "0"; } else if(i2 == 4) { var param1 = document.form1.acc1.value; var param2 = document.form1.acc2.value; var param3 = document.form1.acc3.value; var param4 = document.form1.acc4.value; var param5 = "0"; } else if(i2 == 5) { var param1 = document.form1.acc1.value; var param2 = document.form1.acc2.value; var param3 = document.form1.acc3.value; var param4 = document.form1.acc4.value; var param5 = document.form1.acc5.value; } paramString = ('&acc1=' + param1 + '&acc2=' + param2 + '&acc3=' + param3 + '&acc4=' + param4 + '&acc5=' + param5); top.location.href = ('testing.asp?srt=1' + paramString); }