Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. javascript for check box list

javascript for check box list

Scheduled Pinned Locked Moved Clever Code
javascripttoolshelp
2 Posts 2 Posters 18 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeepakThukral
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • D DeepakThukral

      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

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups