Solved

Confirm to change a radio button

Posted on 2003-12-11
5
715 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:adilkhan
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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

929 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

11 Experts available now in Live!

Get 1:1 Help Now