Welcome Guest, Not a member yet? Register   Sign In
Calling a javascript function from a Controller
#1

[eluser]Unknown[/eluser]
Suppose we have the following files:

1. MyController, a Controller
2. MyView, a View
3. and within MyView, a javascript function titled, "my_js_fn".

Is it possible to call "my_js_fn" from MyController? If so, please provide a simple example.

Thanks for looking.
#2

[eluser]oldmatt[/eluser]
I'm pretty sure you have to call a javascript function with javascript. (Which could be attached to an html attribute)
#3

[eluser]oldrock[/eluser]
Put your Javascript code on the VIEW side (ie) where you load the html code and call your javascript function this both actions should happen only in the view the controller does not relate with javascript codes and funtions.


eg:

in view yourview.php

<html>
<head>
[removed]
function my_js_fn()
{
Your function definition goes here
}

[removed]
</head>
<body>
function can take place anywhere over here.
</body>
</html>
in controller yourcontroller.php

<?php
class Yourcontroller extends Controller
{
function index()
{
$this->load->view('yourview');
}
}
?>




Theme © iAndrew 2016 - Forum software by © MyBB