By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,652 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

Previous radion button checked

Claus Mygind
100+
P: 571
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.
Jul 23 '09 #1
Share this Question
Share on Google+
6 Replies


Canabeez
100+
P: 126
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.
Jul 23 '09 #2

Claus Mygind
100+
P: 571
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?
Jul 23 '09 #3

Canabeez
100+
P: 126
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.  
Jul 23 '09 #4

Claus Mygind
100+
P: 571
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.  
Jul 23 '09 #5

Canabeez
100+
P: 126
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.  
Jul 23 '09 #6

Claus Mygind
100+
P: 571
make sense. Thanks again
Jul 23 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.