Use a variable to store the already selected value.
Use a variable to store the already selected value. HTML Yes No Javascript var alreadySelected=""; $("input"). Click(function(){ if(alreadySelected=="Yes") { alert("You are switching from Yes"); } alreadySelected=$(this).val(); }); EDIT : As per your comment, If one radio button is already checked in the page load,use this code, After the page loads, get the already checked item and store it in the "alreadySelected" variable.
Here is the updated code var alreadySelected=""; $(function(){ alreadySelected=$('inputname=rad:checked').val() }) $("input"). Click(function(){ if(alreadySelected=="Yes") { alert("You are switching from Yes"); } alreadySelected=$(this).val(); }); Here is the working demo : jsfiddle.net/VMKaP/8.
This is almost perfect, but doesn't work if the "Yes" radio button is selected on page load. If you select "No" in this case, the alert does not display. Jsfiddle.Net/VMKaP/6 – Michael 2 days ago @Michael : Read the already selected value in page load.
I updated my answer & the jsfiddle link to handle that scenario. – Shyju 2 days ago.
One way to handle this would be to only apply the handler when the Yes button has been checked and remove it whenever the No button is checked. I'm assuming both start unchecked since otherwise at least one of the buttons would be checked and your second condition would not apply. $('.
Togglevalue="Yes"'). On('change', function() { $('. Togglevalue="No"').
Off('change'); if (this. Checked) { $('. Togglevalue="No"').
On('change', function() { // show your alert }); }); }).
This is close. It works for the first click, but the alert is always displaying after an option is selected. See jsfiddle.Net/HCfsy – Michael 2 days ago @Michael - you're using val() incorrectly.
I think you want 'togglevalue="0"' and 'togglevalue="1"' or use eq. See this updated fiddle: jsfiddle.Net/rar7V I did have an extra space in my selector, which I've now removed. – tvanfosson 2 days ago Gotcha.
Almost there. The div is not hiding again when "No" is selected though. – Michael 2 days ago.
Here is a trick that will do the work - set an invisible field in the page which indicates if the "yes" button was chosen- for ex - now , when the "yes" radio is being checked - fire a function which sets the value of "isYesChosen" to - "yes". Now you can fire the toggle button only when the value of your checking input is "yes" (add a simple if statment in the start of your jquery code). Notice me if you have any trubble.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.