jQuery noobie can't make a checked checkbox show an alert.
        Posted  
        
            by Kyle Sevenoaks
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Kyle Sevenoaks
        
        
        
        Published on 2010-04-26T07:56:15Z
        Indexed on 
            2010/04/26
            8:03 UTC
        
        
        Read the original article
        Hit count: 307
        
I found this answer before, to fire an alert if the button is pressed but the checkbox isn't checked.
Why won't this work?
<input value="1"  type="checkbox" name="salgsvilkar" ID="checkbox2"  style="float:left;"
       onclick="document.getElementById('scrollwrap').style.cssText='border-color:#85c222; background-color:#E5F7C7;';" /><label for="checkbox2" class="akslabel">Salgs og leveringsvilkår er lest og akseptert</label>
        </span>
         {literal}
            <script type="text/javascript">
$(function() {
   //checkbox
   $("#checkbox2").click(function(){
       //if this...
       //alert("this")...
       if($("#checkbox2").is(':checked'))
       {              
          alert("im checked");
       }
   });
   //button
   $("#fullfor_btn").click(function(e){
       if(!$("#checkbox2").is(':checked'))
       {
           alert("you did not check the agree to terms..."); 
           e.preventDefault();
       }
   });
 }
</script>
  {/literal}
This on another .tpl:
<label></label>
        <button type="submit" class="submit" name="{$method}" id="fullfor_btn" title="Fullfør bestillingen nå" value=""> </button>
What could be going wrong? The jQuery doesn't fire anything at all.
© Stack Overflow or respective owner