SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    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>
    Thanks for any help

  2. #2
    SitePoint Zealot
    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

  3. #3
    SitePoint Member
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •