Previous radion button checked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Previous radion button checked

    I have 3 radio buttons - isPartOf, isNotPartOf, and delete

    I do some onscreen subtotaling when the buttons are clicked.

    This a list of contacts and each contact has these 3 radio buttons with a sub-total of the number of contact in the company.

    When the contacts are initially displayed all are part of the group. So the default "isPartOf" is checked.

    The status of each individual can then be changed.

    Clicking either "isNotPartO f" or "delete" will subtract 1 from the count.

    Then clicking "isPartOf" adds 1 back to the count.

    Here is the problem - If the user first clicks "isNotPartO f" that decrements 1 and then clicks "delete" for the same person that decrements again.

    I only want to subtract if the radio button that is being de-selected is "isPartOf"

    So is it possible to know which button was de-selected when "deleted" is selected.
  • Canabeez
    New Member
    • Jul 2009
    • 126

    #2
    It would be easier to understand if you would post the code. Anyhow you can always store the data in Arrays and then compare the data to see what was deselected.

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      In this case there is no code to post. Your point about the array is well taken, but may be more overhead than I am willing to put into the page.

      The question was simply can you detect which button is de-selected in a group of radio buttons when another is selected?

      Comment

      • Canabeez
        New Member
        • Jul 2009
        • 126

        #4
        Maybe this will help you:

        [code=html]
        <html>
        <head>
        <script language="JavaS cript">
        var Selected = '';
        function doSelect(Object )
        {
        alert('The deselected is: ' + Selected + ',\nThe selected is: ' + Object.value);
        Selected = Object.value;
        }
        </script>
        </head>
        <body>
        <input type="radio" name="list" onclick="doSele ct(this)" value="isPartOf ">isPartOf< br>
        <input type="radio" name="list" onclick="doSele ct(this)" value="isNotPar tOf">isNotPartO f<br>
        <input type="radio" name="list" onclick="doSele ct(this)" value="delete"> delete
        </body>
        </html>
        [/code]

        Comment

        • Claus Mygind
          Contributor
          • Mar 2008
          • 571

          #5
          That is very nice. Yes that is what I was looking for. Although on the first selection the alert did not give the deselect.

          I even added the "checked" to the first button

          Code:
           <html>
               <head>
               <script language="JavaScript">
                   var Selected = '';
                   function doSelect(Object)
                   {
                       alert('The deselected is: ' + Selected + ',\nThe selected is: ' + Object.value);
                       Selected = Object.value;
                   }
               </script>
               </head>
               <body>
                   <input type="radio" name="list" onclick="doSelect(this)" checked value="isPartOf">isPartOf<br>
                   <input type="radio" name="list" onclick="doSelect(this)" value="isNotPartOf">isNotPartOf<br>
                   <input type="radio" name="list" onclick="doSelect(this)" value="delete">delete
               </body>
           </html>
          So thank you very much for the help.

          I did solve the problem another way. I removed the "deleted" button when the "isNotPartO f" was selected.

          And then if "isPartOf" was reselected, I restored the button

          use this translation
          exp_ = isPartOf
          rem_ = isNotPartOf
          del_ = delete

          Code:
          	if (cAction == 'rem_')
          	{
          		var elem = document.getElementById("del_"+cKey);
          		elem.parentNode.removeChild(elem);
          	}
          	if (cAction == 'exp_' && !document.getElementById("del_"+cKey))
          	{
          		cVal  = document.getElementById("attr_"+cKey).innerHTML
          		cVal += '<input ';
          		cVal += 'type="radio" ';
          		cVal += 'id="del_'+cKey+'" ' ;
          		cVal += 'onclick="changeStatus(this);" ';
          		cVal += 'value="RemoveFromCompany" ';
          		cVal += 'name="'+cKey+'"/> ' ;
           
          		document.getElementById("attr_"+cKey).innerHTML = cVal
          	}

          Comment

          • Canabeez
            New Member
            • Jul 2009
            • 126

            #6
            No problem ;)

            BTW, adding checked won't fix the problem, you should have set the Selected variable to the default value in the <script>

            [code=html]
            <html>
            <head>
            <script language="JavaS cript">
            var Selected = 'isPartOf';
            function doSelect(Object )
            {
            alert('The deselected is: ' + Selected + ',\nThe selected is: ' + Object.value);
            Selected = Object.value;
            }
            </script>
            </head>
            <body>
            <input type="radio" name="list" onclick="doSele ct(this)" checked value="isPartOf ">isPartOf< br>
            <input type="radio" name="list" onclick="doSele ct(this)" value="isNotPar tOf">isNotPartO f<br>
            <input type="radio" name="list" onclick="doSele ct(this)" value="delete"> delete
            </body>
            </html>
            [/code]

            Comment

            • Claus Mygind
              Contributor
              • Mar 2008
              • 571

              #7
              make sense. Thanks again

              Comment

              Working...