Calling a function within a jQuery plug-in
Posted
by Bob Knothe
on Stack Overflow
See other posts from Stack Overflow
or by Bob Knothe
Published on 2009-06-11T22:56:21Z
Indexed on
2010/04/20
4:03 UTC
Read the original article
Hit count: 284
I am in the process of creating my first jQuery plug-in that will format numbers automatically to various international formats. There are a couple functions within the plug-in that strips the strings and re-formats the string that needs to be called from another jQuery script.
Based on the plug-in structure below (let me know if you need the entire code) can I call and send the parameter(s) to the stripFormat(ii)
and targetFormat(ii, iv)
functions?
Or do I need to change my plug-in structure and if so how?
(function($){
var p = $.extend({
aNum: '0123456789',
aNeg: '-',
aSep: ',',
aDec: '.',
aInput: '',
cPos: 0
});
$.fn.extend({
AutoFormat: function() {
return this.each(function() {
$(this).keypress(function (e){
code here;
});
$(this).keyup(function (e){
code here;
});
// Would like to call this function from another jQuery script - see below.
function stripFormat(ii){
code here;
}
// Would like to call this function from another jQuery script - see below.
function targetFormat(ii, iv){
code here;
}
});
}
});
})(jQuery);
Methods trying to call the plug-in functions:
jQuery(function(){
$("input").change(function (){ //temp function to demonstrate the stripFormat() function.
document.getElementById(targetElementid).value = targetFormat(targetElementid, targetValue);
});
});
I have tried to use these variations without success:
document.getElementById(targetElementid).value = $.targetFormat(targetElementid, targetValue);
document.getElementById(targetElementid).value = $.autoFormat().targetFormat(targetElementid, targetValue);
© Stack Overflow or respective owner