Hi,
This code works in IE, but not in Firefox. I assume it is the way they handle NAME and ID?
Eventually I need to pass the variables to another page and capture them e.g. alacarte_ABC and alacarte_DEF
Should I be using field.name.indexOf("alacarte_") or something? I only know enough to be dangerous...
This code works in IE, but not in Firefox. I assume it is the way they handle NAME and ID?
Eventually I need to pass the variables to another page and capture them e.g. alacarte_ABC and alacarte_DEF
Should I be using field.name.indexOf("alacarte_") or something? I only know enough to be dangerous...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin This function counts all of the alcarte checkboxes and sums it
function findTotals()
{
intBoxCount = 0;
dblTotalCost = 0.0;
chkalacarteGroup = document.getElementsByName('alacarte');
for(i=0;i<chkalacarteGroup.length;i++) {
(chkalacarteGroup[i].type=="checkbox")
if(chkalacarteGroup[i].checked) {
intBoxCount++;
dblTotalCost += 5.99;
}
}
document.getElementById('cost').value = dblTotalCost.toFixed(2);
document.getElementById('clicked').value = intBoxCount;
}
// End -->
<!-- Begin This function does a 'Check All/Uncheck All' test
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
(field[i].name.indexOf("alacarte") == 0 && field[i].name!=field.name)
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
(field[i].name.indexOf("alacarte") == 0 && field[i].name!=field.name)
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
// End -->
</script>
</HEAD>
<body>
<center>
<form name=myform action="" method=post>
<input id="alacarte" name="alacarte_ABC" type="checkbox" value="1">ABC<br>
<input id="alacarte" name="alacarte_DEF" type="checkbox" value="1">DEF<br>
<input id="alacarte" name="alacarte" type="checkbox" value="1">GHI<br>
<input id="alacarte" name="alacarte" type="checkbox" value="1">JKL<br>
<input id="alacarte" name="alacarte" type="checkbox" value="1">MNO<br>
<br>
<br>
Total <input size=5 type=text name=clicked id="clicked" value=0 onfocus=blur()><br>
Cost <input size=5 type=text name=cost id="cost" value=0 onfocus=blur()>
<br>
<br>
<input name="button" type=button class="button" onClick="findTotals()" value="Find totals"><br>
<input type=button class="button" value="Check All" onClick="this.value=check(this.form.alacarte)">
</form>
</center>
</body>
</html>