Welcome Guest, Not a member yet? Register   Sign In
java/ci
#4

[eluser]cahva[/eluser]
First, theres no such thing as a "CI form". Its just a form which was generated with CI's form helper functions. It will output basic html, nothing else Smile

Well you can do the javascript like you would normally do. Create a .js script and put it somewhere where it can be accessed. Lets say you have view hello.php which you will load through controller:
Code:
<!DOCTYPE HTML>
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Some page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    <h1>Hello world!</h1>
    &lt;?=form_open('hello',array('onsubmit' => 'dosomething()')) ?&gt;
    &lt;?=form_submit('submit','Submit') ?&gt;
    &lt;?=form_close() ?&gt;
    &lt; script src="&lt;?=base_url() ?&gt;assets/js/myscript.js"&gt;&lt;/ script>
&lt;/body&gt;
&lt;/html&gt;

You would have that dosomething() function in myscript.js file.

You can also put js code into views and create controller that shows the view. In this case you can include the js like this in the view:
Code:
&lt; script src="&lt;?=site_url('somecontroller/somemethod') ?&gt;"&gt;&lt;/ script>

Controller could be something like this:
Code:
class Somecontroller extends Controller {

    function __construct()
    {
        parent::__construct();
    }
    
    function somemethod()
    {
        $this->load->view('some_view_containing_js');
    }
}

But try to keep your javascript in .js files as much as possible because its always an overhead because you will be parsing the script through PHP and CI. Advantage of outputting the js code from CI/PHP is that you can use php tags inside your scripts and create dynamic js if needed.


Messages In This Thread
java/ci - by El Forum - 09-14-2010, 12:39 AM
java/ci - by El Forum - 09-14-2010, 02:04 AM
java/ci - by El Forum - 09-14-2010, 01:11 PM
java/ci - by El Forum - 09-14-2010, 01:50 PM
java/ci - by El Forum - 09-14-2010, 02:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB