views:

147

answers:

4

I can't figure out why is not working a jquery plugin (base64 encode decode) inside an event function.

This way works:

  $(document).ready(function(){  
    data = $.base64Encode('something');  
    alert(data);  
  });

But when trying to add in an event function, I get the $.base64Encode is not a function error

  $(document).ready(function(){  
    $('#submit').click(function(e){
      data = $.base64Encode('something');  
      alert(data); 
      e.preventDefault();
     }); 
  });

The Jquery plugin is found at: http://plugins.jquery.com/project/base64

A: 

It works for me. You might have an unrelated Javascript error that's causing the base64 library not to load correctly.

clofresh
A: 

in the header i have

<html>
<head>
<title>{TITLE}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen" />
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'&gt;&lt;/script&gt;
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'&gt;&lt;/script&gt;
<script type='text/javascript' src="js/Jquery/jquery.base64.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $('#submit').click(function(e){
        e.preventDefault();
        data = $.base64Encode('something');
    alert(data);
    });
});

</script>
</head>

and a form with the submit button

<input id="submit" type="submit" name="Submit" value="Submit" class="button">

but as I mentioned if i put outside of click function the the data = $.base64Encode('something'); then it works.

More complicating the thing I use Zend Framework and FastTemplate

Kszili
+1  A: 

Nick Craver has right! I use Zfdebug for Zend framework and that already includes JQUERY, and I included twice due to ZF aut include JQUERY. Thank you

I made a new question related to how can I include only once Jquery in a Zfdebug specific environment http://stackoverflow.com/questions/3538849/zfdebug-jquery-interference

Kszili
I made a change and included the plugin before the first Jquery inclusion, now it works, but when I put the application to production (This takes out the first Jquery inclusion then I can't register the plugin on that Jquery) more detailed problem on the upper link
Kszili
+2  A: 

Check that you're not including jQuery twice in the page. What this does is the first one loads, the plugin defines itself on that jQuery object, and when jQuery is included a second time, the window.jQueryobject gets overridden...and the plugin won't be on it :)

You'd see this when running it later, whereas your document.ready might be located before the 2nd jQuery inclusion.

Nick Craver
Please check the other related question of my buddy too, you might know an answer for it: http://stackoverflow.com/questions/3538849/zfdebug-jquery-interference
Pentium10