Solved

Confirm to change a radio button

Posted on 2003-12-11
5
709 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
Comment Utility
change form.scout_access[1].checked=true;
    to
document.agency.scout_access[1].checked = true

Partha
0
 
LVL 23

Expert Comment

by:adilkhan
Comment Utility
Modify to this.....

     else {
 return false;
     }


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

0
 
LVL 31

Expert Comment

by:GwynforWeb
Comment Utility


<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 125 total points
Comment Utility
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
Comment Utility
This line
>>scout_messages.innerHTML

should be

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now