[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Confirm to change a radio button

Posted on 2003-12-11
5
Medium Priority
?
745 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

650 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