0

I need that when clicking on a checkbox, I sent it to a remote url to call a controller in Codeigniter This is what I'm trying to do...

$("#checkbox").click(function() {
   if($("#checkbox").is(':checked')) { 
           alert("go to url"); 
   } else { 
      alert("isnt active"); 
   } 
});
2
  • Are you asking how to make a request to the url? Commented Jun 24, 2013 at 20:14
  • Yes, I want if checkbox is active, go to a url of the controller. Commented Jun 24, 2013 at 20:18

2 Answers 2

2

Use ajax to make the request to the server.

$.ajax({
  url: "http://example.com/controller-name/function-name/parameter1",
  cache: false
}).done(function(data) {
  //Do something with the response.
});

See: http://api.jquery.com/jQuery.ajax/

Sign up to request clarification or add additional context in comments.

Comments

1

you can try this

$("#checkbox").click(function() {
    if($("#checkbox").is(':checked')) { 
       $.ajax({
        url:base_url+'your_controller_name/your_function_name',
        type: 'post',
        data:{any data you want to sent},
        success : function(resp){
            if(resp)
            {
                //do what you want
            }
        },
        error : function(resp){}
       }); 
    } else { 
       alert("isnt active"); 
    } 
});

Please let me know if you face any problem.

UPDATE

May be you want like this.

$("#checkbox").click(function(){
    if($("#checkbox").is(':checked')) { 
        window.location.href="domain_name/your_controller_name/your_function_name"; 
    } else { 
        alert("isnt active"); 
    } 
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.