0

I have a onclick event on a submit button in my CI app. So when user clicks submit, it goes to my js function that disables the button, but it does not continue processing. I used this “document.forms[“mainFrm”].submit();”, but because of the way the code is written I need it to go directly to a controller and finish processing.

So how do I call a CI controller from my js function?

Here is the function that is being called onClick:

function disableWhenSubmit()
{
 alert ("You did get here");
 var holdBtnElement = document.getElementById('btn_Add');
 holdBtnElement.disabled = true;
 holdBtnElement.value = "sending ...";
 //document.forms["createRequestForm"].submit();
 <?= base_url();?>index.php/request"; //this is what I am working on
} 

and here is the button:

input type="submit" id="btn_Add" name="btn_Add" value="Submit"> 
1
  • i think you looking for Ajax Commented Mar 28, 2012 at 16:28

2 Answers 2

1

index.php

<script>
    // create a global var before calling your external
    // javascript file(s).
    var BASE_PATH = "<?php echo base_url();?>";
</script>
<script src="link_to_myjavascript.js"></script>

myjavascript.js (jQuery example)

(function($){

    $(function(){

          var do_ajax = function(some_params){
               $.ajax({
                    url : BASE_PATH + 'controller/method',
               });
          }

          if(conditions)
          {
             do_ajax(some_params);
          }

    });

})(jQuery);
Sign up to request clarification or add additional context in comments.

1 Comment

this seems to be working, I just hid the submit button upon click using jquery: $(document).ready(function(){ $("#btnSubmitJob").click(function(){ $(this).hide(); $("#btnSubmitJob").before("Processing...."); }); });
0

Look at ajax call. Using prototypejs or Jquery

<input type="button" onclick="dosomething()" />

example

<script>
function dosomething() {
  var url = "something.php";
  new Ajax.Request(url, {
    parameters: {//parameters},
    onSuccess: function(transport){
      // do something when response is good
    },
    onFailure: function (request) {
      // Do something when somehting goes wrong     
    });
}
</script>

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.