javascript for check box list
-
I have four check box list on my aspx page. The scenario is that each check box list have check boxes with different-different value. I want that when any user click on those check boxes then sum of value of all selected checkboxes if crosses 1 then it shows a message like that it exceeds 1 i am using the following javascript function
<script type="text/javascript" language="javascript">
//-------------------function hardcode to perform on checklist box--------
var total = 0;
var histvalue = 0;
var valueOfbx = 0;
var currvalue = 0;
function MutExChkList(chk) {
if (chk.checked) {
valueOfbx = 0;
var chklst = chk.parentNode.parentNode.parentNode;
var chkbx = chklst.getElementsByTagName("input");
for (var i = 0; i < chkbx.length; i++) {
if ((chkbx[i].checked == true) && (chkbx[i].value != chk.value)) {
valueOfbx = Number(chkbx[i].value);
histvalue = -1;
chkbx[i].checked = false;
}
else if ((chkbx[i].checked == true) && (chkbx[i].value == chk.value)) {
currvalue = Number(chkbx[i].value);
}
}
total = total + currvalue;
if (histvalue == -1) {
total = total - valueOfbx;
histvalue = 0;
}
if (total > 1) {
total = total - Number(chk.value);
chk.checked = false;
alert("exceeds");
}
else
chkbx[i].checked = false;
}
else {
total = total - Number(chk.value);
}
}</script>
it works perfectly on my system but as i tried to work this on other systems then it does not value of checkboxes Please help me Thanks in advance
-
I have four check box list on my aspx page. The scenario is that each check box list have check boxes with different-different value. I want that when any user click on those check boxes then sum of value of all selected checkboxes if crosses 1 then it shows a message like that it exceeds 1 i am using the following javascript function
<script type="text/javascript" language="javascript">
//-------------------function hardcode to perform on checklist box--------
var total = 0;
var histvalue = 0;
var valueOfbx = 0;
var currvalue = 0;
function MutExChkList(chk) {
if (chk.checked) {
valueOfbx = 0;
var chklst = chk.parentNode.parentNode.parentNode;
var chkbx = chklst.getElementsByTagName("input");
for (var i = 0; i < chkbx.length; i++) {
if ((chkbx[i].checked == true) && (chkbx[i].value != chk.value)) {
valueOfbx = Number(chkbx[i].value);
histvalue = -1;
chkbx[i].checked = false;
}
else if ((chkbx[i].checked == true) && (chkbx[i].value == chk.value)) {
currvalue = Number(chkbx[i].value);
}
}
total = total + currvalue;
if (histvalue == -1) {
total = total - valueOfbx;
histvalue = 0;
}
if (total > 1) {
total = total - Number(chk.value);
chk.checked = false;
alert("exceeds");
}
else
chkbx[i].checked = false;
}
else {
total = total - Number(chk.value);
}
}</script>
it works perfectly on my system but as i tried to work this on other systems then it does not value of checkboxes Please help me Thanks in advance
Psst - this forum is NOT for questions, it's for showing off clever things we have done. Try asking this in Q&A and an answer will be forthcoming. Maybe.
Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett