Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox alert

Status
Not open for further replies.

LeoLionHeart

Programmer
Joined
Apr 4, 2006
Messages
45
Location
GB
Hi there, any help would be greatly appreciated.

I have a server side checkbox on my web form called chkConfirm.
What I want the user to do is when the check box is tick for a confirm/alert message box to appear asking "are you sure you want to delete?" Yes/No.

If the user chooses No then the check box becomes unticked. If Yes the check box stays ticked.

Any ideas? - I know I have to use JScript for this but am unsure how to go about doing this?
 
The problem with the checkbox list is that you will not be able to determine what checkbox in the list was checked.

Jim
 
No it is only one checkbox which is called chkConfirm
 
Oh ok sorry, I thought it was a checkboxlist.

You can try something like this:
Code:
Dim msg as String
msg = "return confirm('Are you sure you want to delete?');"
<YourCheckBox>.Attributes.Add("onclick", msg)

Jim
 
Where should I place this code - In the page load event or Checked changed event. This checkbox is a server side control?

Thanks.
 
A better solution would be this:
Code:
<script>
   function test()
   {
      var i;
      if (document.forms[0].CheckBox1.checked == true)
      {
         i = confirm('Are you sure you want to delete?'); 
         if (i == false)
         {
	    document.forms[0].CheckBox1.checked = false;
         }
       }
   }//end function test()
</script>
add the function between the script tags in the HEAD tags of your HTML. Then in your codebehind do this (Page_Load):
Code:
   <YourCheckBox.Attributes.Add("onclick", "test();")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top