Results 1 to 2 of 2

Thread: check boxes

  1. #1
    Join Date
    Aug 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default check boxes

    Hi,

    I have a check box group.I need to extract the values of each of the checkboxes and also find the maximum value and store it in a hidden variable.Please find the check boxes below.

    <input name='manager' type="checkbox" onclick="return changeManager(this);" value='a_100'> Robin<br>

    <input name='manager' type="checkbox" onclick="return changeManager(this);" value='b_100'> John<br>


    <input name='manager' type="checkbox" onclick="return changeManager(this);" value='c_400'> Smith<br>


    What i need is if the user clicks the check boxes i need to extract the values after the '-' say for example the values 100,100,400 and also the greater of them should be stored in a hidden variable.If the user removes a check box then i have delete them from the array and find the greatest of them afain.Let me know how i can do that.


    Thnx

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What's the point of the whole a_ b_ c_ thing?
    Code:
    <script type="text/javascript">
    String.prototype.getNumberFromOddValue = function() {
      return parseInt(this.substr(this.lastIndexOf("_") + 1));
    }
    var getMaxVal = function(boxes) {
      var e = boxes,
        currMax = e[0].value.getNumberFromOddValue();
      for(var i = 0; i < e.length; i++) if(e[i].value.getNumberFromOddValue() < currMax && e[i].checked) currMax = e[i].value.getNumberFromOddValue();
      return currMax;
    }
    </script>
    
    <input name='manager' type="checkbox" onclick="this.form.elements['biggest'].value=getMaxVal(document.getElementsByName(this.name));return changeManager(this);" value='a_100'> Robin<br>
    
    <input name='manager' type="checkbox" onclick="this.form.elements['biggest'].value=getMaxVal(document.getElementsByName(this.name));return changeManager(this);" value='b_100'> John<br>
    
    <input name='manager' type="checkbox" onclick="this.form.elements['biggest'].value=getMaxVal(document.getElementsByName(this.name));return changeManager(this);" value='c_400'> Smith<br>
    
    <input name="biggest" type="hidden" value="0">
    Untested.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •