Forums | Mahara Community
Developers
/
jquery not working in my plugin page
15 October 2014, 19:40
Hi!!
I'm making a plugin to pop up in my plugin page.
I've page index.tpl from main menu with public static function menu_items() {} in my artefact lib.php.
In my index.tpl I have ;
<script type="text/javascript">
function loadImage() {
alert('test');
}
$(function() {
alert('jquery');
});
</script>
function loadImage is working onclick of <button id="create-user" onclick="loadImage()">Create new user</button>
BUT jquery not working. I donno why?
15 October 2014, 20:04
I found that i did'nt included this <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
in my tpl.
But I SEE THIS IN <script type="text/javascript" src="http://dev.amusedcloud.com/vignesh/mahara192/js/jquery/jquery.js?v=1.9.2"></script> firebug so i thought jquery lib already included.
17 October 2014, 4:57
Hi Vignesh,
I'm not sure what you're trying to do with jQuery here, as you don't need it to fire your alert box.
A more common syntax would be to something like this:
(function($) {
// do something in private scope here, using $ to represent jQuery
})(jQuery);
In that case you have an anonymous function which executes itself. This is good for making sure that the variables you use inside the anonymous function aren't confused with variables in other javascript scripts for the page. With this setup you can be sure that $ in the private scope represents jQuery.
Mike
10 December 2014, 2:58
Thanks Mike,
To include pieforms.js
I have to include src ?
<script src="js/pieforms.js">
</script>
To solve Uncaught ReferenceError: Pieform is not defined
Included in my index.php require_once(dirname(dirname(dirname(__FILE__))).'/lib/pieforms/pieform.php');