I was wondering if anyone can see a way of tidying this up a bit? Maybe using a 'switch' statement. I have never used them before. Is that the best way to tackle this?
Code:
else if (noa == 3)
{
var temp = doco.elements["ad"+sNum].value;
if (activePassNo == 1)
{
if (adtStr.charAt(adtStr.length-1) == "~")
{
adtStr = adtStr.slice(0, -1);
}
doco.elements["ad"+sNum].value = adtStr + tempArr[1] + "~" + tempArr[2];
}
else if (activePassNo == 2)
{
if (adtStr.charAt(adtStr.length-1) == "~")
{
adtStr = adtStr.slice(0, -1);
}
doco.elements["ad"+sNum].value = tempArr[0] + "~" + adtStr + "~" + tempArr[2];
}
else if (activePassNo == 3)
{
if (adtStr.charAt(adtStr.length-1) == "~")
{
adtStr = adtStr.slice(0, -1);
}
doco.elements["ad"+sNum].value = tempArr[0] + "~" + tempArr[1] + "~" + adtStr;
}
else
{
if ((typeof(adtStr) != "undefined") && (typeof(tempArr[parseFloat(activePassNo)]) != "undefined"))
{
doco.elements["ad"+sNum].value = adtStr + tempArr[parseFloat(activePassNo)];
}
else if (typeof(adtStr) != "undefined")
{
doco.elements["ad"+sNum].value = tempArr[0] + "~" + adtStr;
}
else
{
doco.elements["ad"+sNum].value = adtStr;
}
}
}
Picco
www.crmpicco.co.uk