[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Confirm to change a radio button

Posted on 2003-12-11
5
Medium Priority
?
751 Views
Last Modified: 2006-11-17
I have a need to prompt a user for confirmation when changing a radio button.  The problem is that when the user clicks "Cancel" on the prompt, the radio button is still changed instead of the original radio button remaining selected.  Here's my code:
-----------------------------------------------------
function removeAccess() {
     var form = document.agency;
     var accept = confirm("Are you sure you want to remove this user's access?");
     if (accept){
          form.scout_access[0].checked=true;
          form.scout_pi[0].checked=true;
          form.update_scout.value = 'remove';
          scout_messages.innerHTML="<span class='error'>Access will be removed when you click save</span>";
          document.getElementById("saveReminder").style.display = "inline";
     }
     else {
          form.update_scout.value = '0';
          // THIS IS WHAT'S NOT WORKING
          form.scout_access[1].checked=true;
     }
}

<form name="agency" action="..." method="post">
<input type="radio" name="scout_access" value="0" onclick="removeAccess();">
<input type="radio" name="scout_access" value="1" checked="checked">
</form>
-----------------------------------------------------

Everything works fine except for changing the radio button back.  Any suggestions?
0
Comment
Question by:jonbigelow
5 Comments
 
LVL 14

Expert Comment

by:p_partha
ID: 9922954
change form.scout_access[1].checked=true;
    to
document.agency.scout_access[1].checked = true

Partha
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 9923040
Modify to this.....

     else {
 return false;
     }


 > <input type="radio" name="scout_access" value="0" onclick="return removeAccess();">

0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9923056


<form name="agency" action="..." method="post">
<input type="radio" name="scout_access" value="0" onclick="this.checked=removeAccess();">
<input type="radio" name="scout_access" value="1" checked="checked">
</form>
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 375 total points
ID: 9923237
sorry I meant

function removeAccess() {
     var form = document.agency;
     var accept = confirm("Are you sure you want to remove this user's access?");
     if (accept){
          form.scout_access[0].checked=true;
          form.scout_pi[0].checked=true;
          form.update_scout.value = 'remove';
          scout_messages.innerHTML="<span class='error'>Access will be removed when you click save</span>";
          document.getElementById("saveReminder").style.display = "inline";
     }
     else {
          form.update_scout.value = '0';
          // THIS IS WHAT'S NOT WORKING
          form.scout_access[1].checked=true;
     }
return accept
}

<form name="agency" action="..." method="post">
<input type="radio" name="scout_access" value="0" onclick="this.checked=removeAccess();">
<input type="radio" name="scout_access" value="1" checked="checked">
</form>
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9923490
This line
>>scout_messages.innerHTML

should be

document.getElementById('scout_messages').innerHTML = "...."
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question