Hi all,
I have a created sort of a sub list of checkboxes with each of the checkboxes in the sublist having the same name but when I try to loop through any that only contain one checkbox I get an 'Expected Identifier' message.
I loop through the checkboxes when I'm validating if any checkboxes were selected using the .length attribute but that's where the problem lies.
It seems to be because when there is only one checkbox created for a sublist, an array isn't created and hence I can't use the arraay.length function.
Here's the sample tables with the list of checkboxes:
and the javascript I'm using to try and loop through and validate:
Do I need to try and catch if there's an error when using the length attribute and assume there's only one checkbox for that order or is there a tidier way? Any help is greatly appreciated.
Thanks
I have a created sort of a sub list of checkboxes with each of the checkboxes in the sublist having the same name but when I try to loop through any that only contain one checkbox I get an 'Expected Identifier' message.
I loop through the checkboxes when I'm validating if any checkboxes were selected using the .length attribute but that's where the problem lies.
It seems to be because when there is only one checkbox created for a sublist, an array isn't created and hence I can't use the arraay.length function.
Here's the sample tables with the list of checkboxes:
Code:
<TABLE id="S00000001" border=1 BORDERCOLOR="#003366" cellpadding=1 cellspacing=0 STYLE="font-family: Arial, Helvetica, Sans-serif; color: black; font-size: 9pt">
<TR>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Product<BR>Type</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Part<BR>Number</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Part<BR>Description</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Delivery<BR>Date</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Requested<BR>Boxes</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Cancel<BR><input type=checkbox name="completeSOChkBox" onclick="javascript:selDesel('<%=Rs("request number")%>', this)">
</TD>
</TR>
<TR>
<TD align=center>Product 1</TD>
<TD align=center>Part 2</TD>
<TD align=center>Part Description 2</TD>
<TD align=center>11-Mar-09</TD>
<TD align=center>2</TD>
<TD align=center><input type=checkbox name="S00000001partChkBox"></TD>
</TR>
<TD align=center>Product 2</TD>
<TD align=center>Part 3</TD>
<TD align=center>Part Description 3</TD>
<TD align=center>11-Mar-09</TD>
<TD align=center>3</TD>
<TD align=center><input type=checkbox name="S00000001partChkBox"></TD>
</TR>
</TABLE>
<TABLE id="S00000002" border=1 BORDERCOLOR="#003366" cellpadding=1 cellspacing=0 STYLE="font-family: Arial, Helvetica, Sans-serif; color: black; font-size: 9pt">
<TR>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Product<BR>Type</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Part<BR>Number</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Part<BR>Description</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Delivery<BR>Date</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Requested<BR>Boxes</TD>
<TD align=center STYLE="font: 10pt Verdana; color: #003366; font-weight: bold">Cancel<BR><input type=checkbox name="completeSOChkBox" onclick="javascript:selDesel('<%=Rs("request number")%>', this)">
</TD>
</TR>
<TR>
<TD align=center>Product 4</TD>
<TD align=center>Part 6</TD>
<TD align=center>Part Description 6</TD>
<TD align=center>12-Mar-09</TD>
<TD align=center>16</TD>
<TD align=center><input type=checkbox name=S00000001partChkBox"></TD>
</TABLE>
</TD>
</TR>
</TABLE>
and the javascript I'm using to try and loop through and validate:
Code:
function cancelorderValidate(form) {
// Define the required variables for the function
var numOpenRequests = form.completeSOChkBox.length; // number of open Sample Order requests
var validOrderRequest = new Boolean(); // at least one sample requested
var partialSampleCancel = new Boolean(); // partial sample order cancellations
validOrderRequest = false;
// Loop through the orders and check if any complete sample orders have been cancelled
for (i = 0; i < numOpenRequests; i++) {
// Check to see if the Sample order has been cancelled
if (form.completeSOChkBox[i].checked == true) {
validOrderRequest = true;
} else {
var partialSampleCancel = false
var elem = document.getElementById(form.salesOrder[i] + "partChkBox").elements;
// check requested sample parts of the order
for (j = 0; j < elem.length; j++) {
// check if all parts are selected and if so will select whole order
if (eval("form." + form.salesOrder[i] + "partChkBox[" + j + "].checked") == true) {
validOrderRequest = true;
// partial cancellation
} else {
partialSampleCancel = true;
}
}
if (partialSampleCancel == false) {
// show sample order block and select sample order for removal
eval(form.salesOrder[i] + "_exp").style.display = "block";
form.completeSOChkBox[i].checked = true;
}
}
}
}
Do I need to try and catch if there's an error when using the length attribute and assume there's only one checkbox for that order or is there a tidier way? Any help is greatly appreciated.
Thanks