SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Checkbox and alert message
-
Mar 23, 2007, 05:45 #1
- Join Date
- Feb 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Checkbox and alert message
Hi i have what i assume is quite a simple problem. I have a checkbox that by default is checked when i user unchecks it it should show a confirm message. If the user clicks ok it stays unchecked and checked for cancel. The problem i have is if they leave the box unchecked it still gives a message if they decide to check it again i could do with not doing this.
Here's my code:
Code:<input type="checkbox" name="newsletter" checked="checked" onclick="news();"/> <script language="javascript" type="text/javascript"> function news() { var news = confirm("Are you sure you want to avoid our special offer emails?\n\nWe promise you will not be pestered by junk mail. They inform occasionally of releases and special offers. You can unsubscribe at anytime!"); if (document.reg.newsletter.checked==false) { //document.forms[0].elements['newsletter'].checked = checkbox_status if (news == true) { document.reg.newsletter.checked=false; } else { document.reg.newsletter.checked=true; } } if (document.reg.newsletter.checked==true) { "It should do nothing here" } } </script>
-
Mar 23, 2007, 07:31 #2
- Join Date
- Nov 2005
- Posts
- 113
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just add a counter in there.
var counter = 0;
if checkbox unchecked, counter = counter + 1;
then if counter more than 1, don't show alert
-
Mar 23, 2007, 09:22 #3
- Join Date
- Feb 2007
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
easy - perfect thanks very much didn't even think of that. My brain just farts when it comes to js.
Cheers
Bookmarks