Question

I want to write a function in jQuery that when a user click on a checkbox a textfield-2 becomes enabeled and required and textfield-1 becomes disabled. if checkbox is not checked, the textfield-2 is disabled and not required and textfield-1 is enabeled.

So is like a toggle between these 2 textfield. the form is sth like this:

   <form id="link" name="link" action="post">
   <input type="checkbox" name="url_type" id="url_type"  >
   <input type="text" name="textfield1" id="textfield1">
   <input type="text" name="textfield2" id="textfield2" disable="disable">
   <input type="submit" name="send" value="send">
   </form>

And the jQuery Code looks like this:

 <script type="text/javascript"> 
    $('#url_type').on('change',function(){
       var checked=$('#url_type').is(':checked');
        if(checked==true)
        {   
            $('#textfield1').attr('disabled',true);
            $('#textfield2').attr('disabled',false);
        } else {

            $('#textfield1').attr('disabled',false);
            $('#textfield2').attr('disabled',true);
        }
      });
</script>

The problem i have is that at cakephp when i create a new link, if the checkbox is not selected works fine, but if i check the checkbox, ( meaning that textfield2 becomes enabled and textfield1 disabled ) it generate an error that looks like this:

The request has been black-holed Error: The requested address was not found on this server.

I donn't know where the conflict is or what is generating that error!

Was it helpful?

Solution

You can handle the Blackhole issue.

Put the following line in beforeFilter method of your controller class file.

$this->Security->blackHoleCallback = 'blackhole';

Now, create a function in the same controller file:

public function blackhole($type) {
// handle errors.
}

This post can also help you to overcome this issue.

OTHER TIPS

Adapt your form tag: 1. use type: post 2. type an url in attribute action, where your form should be sent (/name of Controller/name of Action)

   <form id="link" name="link" method="post" action="/controller/action">
   <input type="checkbox" name="url_type" id="url_type"  >
   <input type="text" name="textfield1" id="textfield1">
   <input type="text" name="textfield2" id="textfield2">
   <input type="submit" name="send" value="send">
   </form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top