?
Solved

Confirm to change a radio button

Posted on 2003-12-11
5
Medium Priority
?
738 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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

752 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