views:

30

answers:

2

Hi, I am writing a bookmarklet in which I want to use the jquery forms plugin.

The problem I am having is that a web page on which the bookmarklet might be used could be using a different js lib, which already uses '$'. No problem, I can tell jQuery to use noConflict()

However, the forms plugin of jQuery also uses '$' which I have no control over. Is there a way for me to specify to this plugin to not use $ and use jQuery instead?

More details..

As TNi suggests, I might be misunderstanding the problem.

Here is what I do

I am using Safari 5. Here is what I do (jquery already loaded) ....

var scriptElem = docEl.createElement('script');
scriptElem.setAttribute('src',"http://localhost:81/p/a2b/jquery.form.js");
scriptElem.setAttribute('type','text/javascript');
document.getElementsByTagName('head')[0].appendChild(scriptElem);

and then

jQuery(docEl).ready(function() {
    jQuery('#a2b_cart').ajaxForm(function () { alert (" yo");});

});

What I see on the javascript console:

jQuery("#a2b_cart").ajaxForm is not a function
+2  A: 

The Form Plugin uses a technique that allows it to use $ locally within its own code without conflicting with any calls to jQuery.noConflict().

When you are setting up your form to be handled by the plugin, just use jQuery in place of $. If the problem still persists, we will need to see specific code in order to help.

TNi
TNi, thanks for the response. I have added more details. It is possible that I have a different problem, based on the info you provided.
Sid
A: 

Chances are, your code initializing the form is called immediately after adding the script element, but before it has loaded. Since jQuery is already loaded, call the forms file via getScript:

jQuery.getScript("http://localhost:81/p/a2b/jquery.form.js", function () {
    jQuery('#a2b_cart').ajaxForm(function () { alert("yo"); });

    // Rest of your code here, or call out to another function
});

// Don't place code here, form.js hasn't loaded yet.

The callback function will only be run once the script file has loaded.

Doug Neiner
Thanks Doug(and TNi). That was the problem
Sid