southbeach
Programmer
I have a JS function:
The HTML looks like this:
As you may have noticed, I am using field names such as ship[], isBD[], etc. I am getting a JS error saying that toship[] is not defined. Notice that I am defining it within the JS snippet.
The code works if I have two or more input lines but it breaks on a single line. I have spent all day looking at this and no matter what, I cannot see what's wrong with it.
Perhaps, I am so convinced that it should work that I am blocking an obvious problem.
Thank you all for your help!
--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
Code:
function clicked(n)
{
isBD=document.forms[0].elements["isBD[]"];
isHZ=document.forms[0].elements["isHZ[]"];
isOV=document.forms[0].elements["isOV[]"];
isFUM=document.forms[0].elements["isFUM[]"];
pcs=document.forms[0].elements["pcs[]"];
wgt=document.forms[0].elements["wgt[]"];
vwgt=document.forms[0].elements["vwgt[]"];
povalue=document.forms[0].elements["povalue[]"];
toship=document.forms[0].elements["ship[]"];
totalPCS=document.getElementById('totalPCSID').value;
totalKGS=document.getElementById('totalKGSID').value;
totalVKGS=document.getElementById('totalVKGSID').value;
totalVAL=document.getElementById('totalVALID').value;
bdPCS=document.getElementById('bdPCSID').value;
ovPCS=document.getElementById('ovPCSID').value;
fumPCS=document.getElementById('hzPCSID').value;
hzPCS=document.getElementById('fumPCSID').value;
if (toship[n].checked == true) {
piezas=pcs[n].value;
if (piezas == 'COPACK') piezas=0;
totalPCS=(1*totalPCS)+(1*piezas);
totalKGS=(1*totalKGS)+(1*wgt[n].value);
totalVKGS=(1*totalVKGS)+(1*vwgt[n].value);
totalVAL=(1*totalVAL)+(1*povalue[n].value);
if (isBD[n].value == 'Y' || isBD[n].value == 'y') bdPCS=(1*bdPCS)+(1*piezas);
if (isHZ[n].value == 'Y' || isHZ[n].value == 'y') hzPCS=(1*hzPCS)+(1*piezas);
if (isOV[n].value == 'Y' || isOV[n].value == 'y') ovPCS=(1*ovPCS)+(1*piezas);
if (isFUM[n].value == 'Y' || isFUM[n].value == 'y') fumPCS=(1*fumPCS)+(1*piezas);
} else {
piezas=pcs[n].value;
if (piezas == 'COPACK') piezas=0;
totalPCS=(1*totalPCS)-(1*piezas);
totalKGS=(1*totalKGS)-(1*wgt[n].value);
totalVKGS=(1*totalVKGS)-(1*vwgt[n].value);
totalVAL=(1*totalVAL)-(1*povalue[n].value);
if (isBD[n].value == 'Y' || isBD[n].value == 'y') bdPCS=(1*bdPCS)-(1*piezas);
if (isHZ[n].value == 'Y' || isHZ[n].value == 'y') hzPCS=(1*hzPCS)-(1*piezas);
if (isOV[n].value == 'Y' || isOV[n].value == 'y') ovPCS=(1*ovPCS)-(1*piezas);
if (isFUM[n].value == 'Y' || isFUM[n].value == 'y') fumPCS=(1*fumPCS)-(1*piezas);
}
document.getElementById('totalPCSID').value=totalPCS;
document.getElementById('totalKGSID').value=formatAsMoney(totalKGS);
document.getElementById('totalVKGSID').value=formatAsMoney(totalVKGS);
document.getElementById('totalVALID').value=formatAsMoney(totalVAL);
document.getElementById('bdPCSID').value=bdPCS;
document.getElementById('ovPCSID').value=ovPCS;
document.getElementById('hzPCSID').value=hzPCS;
document.getElementById('fumPCSID').value=fumPCS;
xajax_clicked(totalPCS,totalKGS,totalVKGS,totalVAL,bdPCS,ovPCS,hzPCS,fumPCS);
}
The HTML looks like this:
Code:
<input type="checkbox" name="ship[]" id="ship0ID" value="0" onclick="clicked('0')" />
As you may have noticed, I am using field names such as ship[], isBD[], etc. I am getting a JS error saying that toship[] is not defined. Notice that I am defining it within the JS snippet.
The code works if I have two or more input lines but it breaks on a single line. I have spent all day looking at this and no matter what, I cannot see what's wrong with it.
Perhaps, I am so convinced that it should work that I am blocking an obvious problem.
Thank you all for your help!
--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.