Results 1 to 2 of 2

Thread: Checking the value of checkbox

  1. #1
    Join Date
    Jan 2013

    Checking the value of checkbox


    I have written the following javascript: http://ectpro.co/calc/rate.html

    What I need to is if the user places a checkmark in either the
    Starter Pack
    Extended Pack
    Development Pack or
    Paymate Pack

    then the quantity of the checked item will be set to "1" and the rest will be set to "0".

    Here is a zipped copy of my code:

    Thanks for any help

  2. #2
    Join Date
    Dec 2005
    Your 'rate.html' link is broken.

    Your 'calc2.zip' file does not contain any of the checkmark elements you mention.

    Finally, the requirements you specify are better served with a radio button rather than a checkbox.
    Your value for a particular element selected by the user can be determined by looking for the only TRUE
    item checked in the radio button named group.

    Consider this...
    <!DOCTYPE html>
    <html lang="en">
    <meta charset="UTF-8" />
    <title> HTML5 page </title>
    <fieldset style="width:10em">
     <legend> Available Packs </legend>
     <input type="radio" name="packs" value="Starter Pack"> Starter Pack <br>
     <input type="radio" name="packs" value="Extended Pack"> Extended Pack <br>
     <input type="radio" name="packs" value="Development Pack"> Development Pack <br>
     <input type="radio" name="packs" value="Paymate Pack"> Paymate Pack
    <button onclick="showPack()">Show selection</button>
    <script type="text/javascript">
    // From: http://www.webdeveloper.com/forum/showthread.php?296007-Checking-the-value-of-checkbox
    function getRBtnName(GrpName) {
      var sel = document.getElementsByName(GrpName);
      var fnd = -1;
      var str = '';
      for (var i=0; i<sel.length; i++) {
        if (sel[i].checked) { str = sel[i].value;  fnd = i; }
    //  return fnd;   // return option index of selection
    // comment out next line if option index used in line above  
      return str;
    function showPack() {
      var pick = getRBtnName('packs');
      if (pick == '') { alert('No selection chosen'); }
                 else { alert('User choice: '+pick); }
    Last edited by JMRKER; 06-05-2014 at 09:32 PM. Reason: Added example

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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