473,480 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Previous radion button checked

Claus Mygind
571 Contributor
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
6 2075
Canabeez
126 New Member
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
571 Contributor
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
126 New Member
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
571 Contributor
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
126 New Member
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
571 Contributor
make sense. Thanks again
Jul 23 '09 #7

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

Similar topics

4
4082
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
3
2326
by: ewitkop90 | last post by:
Here is my code: <SCRIPT> function transportchange(transport) { if (framenewinstall.Helpdesk.checked) framenewinstall.Helpdesk.checked=false; if (framenewinstall.CircuitNumber.checked)...
0
1943
by: hy | last post by:
Hi all, I got the question about the radio button. How do i detect previous checked radio button after i checked other's radio button. While the new radio button checked, it need to prompt out a...
3
1373
by: Robert Bull | last post by:
I am trying to add a radio button at runtime in an asp.net web form but I keep getting the error message "type 'RadioButton' must be placed inside a form tag with runat=server". I use the following...
2
3152
by: Joey | last post by:
Hi There, I am trying to get the selected value of a listbox when I click a button, everything works ok and I can bind the list and when I have a basic page and click a button to invoke a sub it...
1
1400
by: puja | last post by:
hi all, I have a form which has checkbox list which has items as below 1) Input 1 2) Input 2 3) Input 3 4) Input 4 5) Input 5
1
1909
by: George Ter-Saakov | last post by:
I am trying to set class property of the radio button. but no mater what i do .NET moves it to <SPANtag aroung that radio button. So my <asp:RadioButton id="chkAllUpdates" cssClass="radio"...
3
1280
by: tragic54 | last post by:
Alright so i've come across a problem. Basically what i have is 3 seperate radio buttons within a panel labeled ( tall, huge, bucket) I'm trying to return values from check boxes once the choice of...
2
1787
by: TheSouthLondonSlasher | last post by:
Thank you in advance to anyone who may be able to help. This is my first attempt at JavaScript, so I apologize if I've done something blatantly stupid in the below code. Basically, I have a form...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.