Search code examples
codeignitergrocery-crud

Adding javascript function to a grocerycrud add or edit form


Is it possible to add a javascript function to the add/edit forms of grocery_CRUD?

E.g. As a user is typing in a particular field when adding or editing a record I want to execute a javascript on the keydown event.

If so, how?


Solution

  • It is possible. For example, you call the view like this:

    $this->load->view('grocery_crud_view', $output);
    

    In the beginning of the view (grocery_crud_view.php), you can add any javascript

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascrpt">
        $("#field-code").keyup(function(){
           alert("there is a keyup");
        });
    </script>
    <?php
    // The rest of default php code
    ?>
    

    Most of the id of the grocery-CRUD view (if you use flexigrid theme) would be something like this : "field-your_field_name" You can inspect with firebug or google-chrome developer tools to ensure it.