Connecting Tech Pros Worldwide Forums | Help | Site Map

Previous radion button checked

Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#1: Jul 23 '09
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 "isNotPartOf" 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 "isNotPartOf" 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's Avatar
Member
 
Join Date: Jul 2009
Location: Israel
Posts: 85
#2: Jul 23 '09

re: Previous radion button checked


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.
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#3: Jul 23 '09

re: Previous radion button checked


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?
Canabeez's Avatar
Member
 
Join Date: Jul 2009
Location: Israel
Posts: 85
#4: Jul 23 '09

re: Previous radion button checked


Maybe this will help you:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.     <script language="JavaScript">
  4.         var Selected = '';
  5.         function doSelect(Object)
  6.         {
  7.             alert('The deselected is: ' + Selected + ',\nThe selected is: ' + Object.value);
  8.             Selected = Object.value;
  9.         }
  10.     </script>
  11.     </head>
  12.     <body>
  13.         <input type="radio" name="list" onclick="doSelect(this)" value="isPartOf">isPartOf<br>
  14.         <input type="radio" name="list" onclick="doSelect(this)" value="isNotPartOf">isNotPartOf<br>
  15.         <input type="radio" name="list" onclick="doSelect(this)" value="delete">delete
  16.     </body>
  17. </html>
  18.  
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#5: Jul 23 '09

re: Previous radion button checked


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

Expand|Select|Wrap|Line Numbers
  1.  <html>
  2.      <head>
  3.      <script language="JavaScript">
  4.          var Selected = '';
  5.          function doSelect(Object)
  6.          {
  7.              alert('The deselected is: ' + Selected + ',\nThe selected is: ' + Object.value);
  8.              Selected = Object.value;
  9.          }
  10.      </script>
  11.      </head>
  12.      <body>
  13.          <input type="radio" name="list" onclick="doSelect(this)" checked value="isPartOf">isPartOf<br>
  14.          <input type="radio" name="list" onclick="doSelect(this)" value="isNotPartOf">isNotPartOf<br>
  15.          <input type="radio" name="list" onclick="doSelect(this)" value="delete">delete
  16.      </body>
  17.  </html>
So thank you very much for the help.

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

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

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

Expand|Select|Wrap|Line Numbers
  1.     if (cAction == 'rem_')
  2.     {
  3.         var elem = document.getElementById("del_"+cKey);
  4.         elem.parentNode.removeChild(elem);
  5.     }
  6.     if (cAction == 'exp_' && !document.getElementById("del_"+cKey))
  7.     {
  8.         cVal  = document.getElementById("attr_"+cKey).innerHTML
  9.         cVal += '<input ';
  10.         cVal += 'type="radio" ';
  11.         cVal += 'id="del_'+cKey+'" ' ;
  12.         cVal += 'onclick="changeStatus(this);" ';
  13.         cVal += 'value="RemoveFromCompany" ';
  14.         cVal += 'name="'+cKey+'"/> ' ;
  15.  
  16.         document.getElementById("attr_"+cKey).innerHTML = cVal
  17.     }
  18.  
Canabeez's Avatar
Member
 
Join Date: Jul 2009
Location: Israel
Posts: 85
#6: Jul 23 '09

re: Previous radion button checked


No problem ;)

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

Expand|Select|Wrap|Line Numbers
  1.  <html>
  2.      <head>
  3.      <script language="JavaScript">
  4.          var Selected = 'isPartOf';
  5.          function doSelect(Object)
  6.          {
  7.              alert('The deselected is: ' + Selected + ',\nThe selected is: ' + Object.value);
  8.              Selected = Object.value;
  9.          }
  10.      </script>
  11.      </head>
  12.      <body>
  13.          <input type="radio" name="list" onclick="doSelect(this)" checked value="isPartOf">isPartOf<br>
  14.          <input type="radio" name="list" onclick="doSelect(this)" value="isNotPartOf">isNotPartOf<br>
  15.          <input type="radio" name="list" onclick="doSelect(this)" value="delete">delete
  16.      </body>
  17.  </html>
  18.  
Claus Mygind's Avatar
Familiar Sight
 
Join Date: Mar 2008
Posts: 173
#7: Jul 23 '09

re: Previous radion button checked


make sense. Thanks again
Reply